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
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