Flicker problem, DirectDraw 9/VB .NET

Darc

Well-known member
Joined
Apr 18, 2003
Messages
89
Hey, I just got DirectDraw going only to find that it flickers like crazy. Heres 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
 
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:
Code:
application.startuppath & "someimage"

all you have to do is say, "someimage"

and when you Dim integers, you dont have to say theyre 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 theres no spaces between the square bracket and vb(i didnt put it there because.. well, then youd 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+
 
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 theres a problem with my settings... somewhere. Ive 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++
 
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.
 
Last edited by a moderator:
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?
 
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.
 
Er.. you shouldnt 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 thats just a guess, I actually dont use DirectDraw. :)
 
Back
Top