Darc Posted August 17, 2003 Posted August 17, 2003 Hey, I just got DirectDraw going only to find that it flickers like crazy. Here's the code, any help is appreciated. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load objDD = New clsDD(ddDevice, Me, 800, 600) Dim ck As New ColorKey() ck.ColorSpaceHighValue = 0 ck.ColorSpaceLowValue = 0 Sprite = New clsDDSpr(Windows.Forms.Application.StartupPath & "\SomeImage", 2, ddDevice, ck) objDD.fillBuff(50) Dim x As Integer = 0 Dim y As Integer = 0 Do objDD.fillBuff(50) objDD.Blt(Sprite.Frame(0), x, y, Sprite.FrameRect) objDD.Blt(Sprite.Frame(1), 50, 100, Sprite.FrameRect) objDD.flipBack() System.Threading.Thread.Sleep(75) Windows.Forms.Application.DoEvents() y += 10 x += 10 Loop End Sub objDD is a class I made to hold all the surfaces. heres the initialization code: Public Sub New(ByRef ddDevice As Device, ByRef ctrl As Control, ByVal ScreenWidth As Int32, ByVal ScreenHeight As Int32) ddDevice = New Device(CreateFlags.Default) ddDevice.SetDisplayMode(ScreenWidth, ScreenHeight, 16, 0, False) ddDevice.SetCooperativeLevel(ctrl, CooperativeLevelFlags.FullscreenExclusive) srfDscFront = New SurfaceDescription() srfDscFront.SurfaceCaps.Flip = True srfDscFront.SurfaceCaps.PrimarySurface = True srfDscFront.SurfaceCaps.Complex = True srfDscFront.BackBufferCount = 1 srfFront = New Surface(srfDscFront, ddDevice) srfDscFront.Clear() Dim myCaps As New SurfaceCaps() myCaps.BackBuffer = True srfBack = srfFront.GetAttachedSurface(myCaps) End Sub 'The Class' functions Public Function fillBuff(ByVal col As Integer) As Boolean fillBuff = False srfFront.ColorFill(col) srfBack.ColorFill(col) Return True End Function Public Function Blt(ByVal srfFrame As Surface, ByVal x As Int32, ByVal y As Int32, ByVal rct As Rectangle) As Boolean Blt = False rct.X = x rct.Y = y If rct.Y + rct.Height > 600 Then rct.Y = 600 - rct.Height If rct.X + rct.Width > 800 Then rct.X = 800 - rct.Width srfBack.Draw(rct, srfFrame, DrawFlags.KeySource Or DrawFlags.DoNotWait) Return True End Function Public Function flipBack() As Boolean flipBack = False srfFront.Flip(srfBack, FlipFlags.DoNotWait) Return True End Function Quote
ThePentiumGuy Posted August 17, 2003 Posted August 17, 2003 please put this post in the DirectX section under Graphics, thanks I dont know much about DirectX but i believe that this site may help: http://www.directx4.net Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Darc Posted August 17, 2003 Author Posted August 17, 2003 bleh, completely didn't see I was in Graphics LOL Quote
ThePentiumGuy Posted August 17, 2003 Posted August 17, 2003 i have a tip for you: store all your graphics/sound in the Bin folder of your application, so that wen you access it, you dont have to say: application.startuppath & "someimage" all you have to do is say, "someimage" and when you Dim integers, you dont have to say they're 0.. they are 0 by default :p (one more thing, if ur posting a huge amount of VB code, use this before and after the code your typing: [ vb ] and [ /vb ] make sure there's no spaces between the square bracket and vb(i didnt put it there because.. well, then you'd see a box of empty code)) DirectDraw flickers?! I always thought DirectDraw was supposed to be fast! have u tried using GDI+ for your program? I would use GDI+ if its not a Huge program, if its a pretty small application use GDI+ Quote My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!) vbprogramming.8k.com My Project (Need VB.NET Programmers) http://workspaces.gotdotnet.com/ResolutionRPG
Darc Posted August 17, 2003 Author Posted August 17, 2003 ok, first for the "someimage" thing, I used to juse say "someimage" until it started giving me file not found errors, then as for DirectDraw flickering, I think its because there's a problem with my settings... somewhere. I've always used DD 7/VB 6 but I prefer .NET to 6 and the settings have changed... As well, Dim ___ as integer = 0 is a habit... no clue why, maybe C or C++ Quote
*Experts* mutant Posted August 17, 2003 *Experts* Posted August 17, 2003 (edited) Sorry that I cant help you much now, but I can tell you that this not a problem with DirectDraw. I remeber solving this problem but now I dont remeber what caused it and how to fix it, Ill try to reproduce this. Edited August 17, 2003 by mutant Quote
Darc Posted August 17, 2003 Author Posted August 17, 2003 I got the flicker down alot by setting the form to TopMost but whatever the last image that I blitted was seems to flicker, all the rest is fine. Any help? Quote
Darc Posted August 17, 2003 Author Posted August 17, 2003 I fixed it!!! Right after you finish the last Blt, use Threading.Thread.Sleep() for 2 milliseconds. I think the Surface is just trying to flip while its still drawing. Quote
wyrd Posted August 17, 2003 Posted August 17, 2003 Er.. you shouldn't have to do that (plus, in my experience Threading.Thread.Sleep() actually slowed my game down by 5fps). It sounds like you might not be using the right DrawFlags or FlipFlags. Of course that's just a guess, I actually don't use DirectDraw. :) Quote Gamer extraordinaire. Programmer wannabe.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.