I try to make a simple game, but when I create Graphics it flicker where bad. Even then I use a back buffer (double buffering). I draw to a Panel and not full screen.
First I create surface like this.
DDDevice = New Device(CreateFlags.Default)
DDDevice.SetCooperativeLevel(Panel, CooperativeLevelFlags.Normal)
CK.ColorSpaceHighValue = RGB(0, 0, 0)
CK.ColorSpaceLowValue = RGB(0, 0, 0)
SDesc.SurfaceCaps.PrimarySurface = True
FrontSurface = New Surface(SDesc, DDDevice)
SDesc.SurfaceCaps.PrimarySurface = False
SDesc.SurfaceCaps.OffScreenPlain = True
SDesc.SurfaceCaps.VideoMemory = True
SDesc.Height = Panel.Bottom - Panel.Top
SDesc.Width = Panel.Right - Panel.Left
BackSurface = New Surface(SDesc, DDDevice)
BackSurface.SetColorKey(ColorKeyFlags.SourceDraw, CK)
Clip = New Clipper(DDDevice)
Clip.Window = Panel
FrontSurface.Clipper = Clip
SDesc.Clear()
SDesc.SurfaceCaps.OffScreenPlain = True
SpriteSurface = New Surface("Sprite.bmp", SDesc, DDDevice)
SpriteSurface.SetColorKey(ColorKeyFlags.SourceDraw, CK)
SDesc.Clear()
SDesc.SurfaceCaps.OffScreenPlain = True
MapSurface = New Surface("BackGround.bmp", SDesc, DDDevice)
When I draw I do this.
Try
BackSurface.ColorFill(Color.Blue)
BackSurface.DrawFast(0, 0, MapSurface, Map.Rect, DrawFastFlags.DoNotWait)
BackSurface.DrawFast(0, 0, SpriteSurface, DrawFastFlags.SourceColorKey)
Catch ex As SurfaceLostException
InitializeSurface()
End Try
Dest = New Rectangle(PointToScreen(Panel.Location), Panel.ClientSize)
FrontSurface.Draw(Dest, BackSurface, DrawFlags.Wait)
Why does this program flicker so badly?
First I create surface like this.
DDDevice = New Device(CreateFlags.Default)
DDDevice.SetCooperativeLevel(Panel, CooperativeLevelFlags.Normal)
CK.ColorSpaceHighValue = RGB(0, 0, 0)
CK.ColorSpaceLowValue = RGB(0, 0, 0)
SDesc.SurfaceCaps.PrimarySurface = True
FrontSurface = New Surface(SDesc, DDDevice)
SDesc.SurfaceCaps.PrimarySurface = False
SDesc.SurfaceCaps.OffScreenPlain = True
SDesc.SurfaceCaps.VideoMemory = True
SDesc.Height = Panel.Bottom - Panel.Top
SDesc.Width = Panel.Right - Panel.Left
BackSurface = New Surface(SDesc, DDDevice)
BackSurface.SetColorKey(ColorKeyFlags.SourceDraw, CK)
Clip = New Clipper(DDDevice)
Clip.Window = Panel
FrontSurface.Clipper = Clip
SDesc.Clear()
SDesc.SurfaceCaps.OffScreenPlain = True
SpriteSurface = New Surface("Sprite.bmp", SDesc, DDDevice)
SpriteSurface.SetColorKey(ColorKeyFlags.SourceDraw, CK)
SDesc.Clear()
SDesc.SurfaceCaps.OffScreenPlain = True
MapSurface = New Surface("BackGround.bmp", SDesc, DDDevice)
When I draw I do this.
Try
BackSurface.ColorFill(Color.Blue)
BackSurface.DrawFast(0, 0, MapSurface, Map.Rect, DrawFastFlags.DoNotWait)
BackSurface.DrawFast(0, 0, SpriteSurface, DrawFastFlags.SourceColorKey)
Catch ex As SurfaceLostException
InitializeSurface()
End Try
Dest = New Rectangle(PointToScreen(Panel.Location), Panel.ClientSize)
FrontSurface.Draw(Dest, BackSurface, DrawFlags.Wait)
Why does this program flicker so badly?