Superfly1611
Regular
Hello
I'm building a 2D game that runs in a full screen resolution of 640*480 using vb.net and directdraw
But i have a problem.
What i want to do is create a surface in memory that stores the images that make up my level (walls, floor, etc).
Then create another surface in memory and draw (based on a 2D string array) my level to that surface.
This new surface would then be drawn to my backbuffer before flipping my surfaces.
Here is what i've got in my graphics class(This is based on tutorials @ Directx4.Net....
The error i get is when i try and draw the structuresurface to the back buffer simply points out the line it occured on (highlighted in red)
Can someone tell me where i'm going wrong?
Do i need to set some kind of property on the surface?
I'm building a 2D game that runs in a full screen resolution of 640*480 using vb.net and directdraw
But i have a problem.
What i want to do is create a surface in memory that stores the images that make up my level (walls, floor, etc).
Then create another surface in memory and draw (based on a 2D string array) my level to that surface.
This new surface would then be drawn to my backbuffer before flipping my surfaces.
Here is what i've got in my graphics class(This is based on tutorials @ Directx4.Net....
Code:
Private targetform As Form = Nothing
Private dddevice As Device = Nothing 'DirectDraw Device
Private psurface As Surface = Nothing 'Primary Surface
Private ssurface As Surface = Nothing 'Backbuffer
Private LevelSurface As Surface = Nothing 'Background surface
Private StructuresSurface As Surface = Nothing 'Surface containing bitmaps of all differnt objects(walls,floors etc)
Private FullScreenRect As New Rectangle(0, 0, 640, 480) 'Rect to draw to the screen with
Private clip As Clipper = Nothing
Private needrestore As Boolean = False
Private StructureFrames(3) As Rectangle 'Rect for each structure bitmap
'Variables for FPS limiter - not relevant
Private thisTick As Integer
Private lastTick As Integer = Environment.TickCount
Private sinceLastTick As Integer
Private Const fps As Integer = 9
'Map informationn
Private height, width As Integer
Private MapArray(9, 9) as integer
Public Sub New(ByVal frm As Form)
targetform = frm
InitDevice()
LoadLevelSurface()
End Sub
Public Sub InitDevice()
'Create Device
dddevice = New Device
'Give device full control of the screen
dddevice.SetCooperativeLevel(targetform, CooperativeLevelFlags.FullscreenExclusive)
'Set display resolution and color depth
dddevice.SetDisplayMode(640, 480, 32, 85, False)
'Create Surfaces
InitSurfaces()
End Sub
Private Sub InitSurfaces()
'Create Primary and Secondary Game Surfaces
Dim sdesc As New SurfaceDescription
clip = New Clipper(dddevice)
clip.Window = targetform
sdesc.SurfaceCaps.PrimarySurface = True
sdesc.SurfaceCaps.Flip = True
sdesc.SurfaceCaps.Complex = True
sdesc.BackBufferCount = 1
psurface = New Surface(sdesc, dddevice)
psurface.Clipper = clip
sdesc.Clear()
sdesc.SurfaceCaps.BackBuffer = True
ssurface = psurface.GetAttachedSurface(sdesc.SurfaceCaps)
sdesc.Clear()
'Craete Surface with the 4 structure images in it
StructuresSurface = New Surface("images/levelstructures.bmp", sdesc, dddevice)
'Create Level Surface which we will build the level graphics on to
LevelSurface = New Surface(sdesc, dddevice)
End Sub
Private Sub LoadLevelSurface()
CreateStructureFrames()
Dim i, j As Integer
'For each row in array
For i = 0 To mapheight - 1
'for each column in that row
For j = 0 To mapWidth - 1
'Draw the Appropriate structure in the coresponding position (determined by the value in the MapArray array
LevelSurface.DrawFast((j * 64), (i * 48), StructuresSurface, StructureFrames(mapArray(j,i)), DrawFastFlags.Wait)
Next
Next
End Sub
Private Sub CreateStructureFrames()
Dim x As Integer
For x = 0 To 3
'Each image in the bitmap is 64*48 pixels
StructureFrames(x) = New Rectangle((x * 48), 0, 64, 48)
Next
End Sub
Public Sub FlipSurface()
If dddevice.TestCooperativeLevel = False Then 'if the device is not ready
needrestore = True 'indicate that there is a need to restore surfaces
Return 'return
End If
If needrestore Then 'if need to restore
needrestore = False 'turn the flag to false
dddevice.RestoreAllSurfaces() 'restore surfaces
End If
Try
'Fill Background
ssurface.ColorFill(Color.Black)
'Draw LevelSurface surface to back buffer
[color=red][b]ssurface.DrawFast(0, 0, LevelSurface, FullScreenRect, DrawFastFlags.Wait)[/b][/color]
'Flip Surfaces
psurface.Flip(ssurface, FlipFlags.Wait)
'Limit the FPS
LimitFPS()
Catch ex As Exception
MsgBox(ex.ToString(), MsgBoxStyle.OKOnly)
Dispose()
End
End Try
End Sub
Public Sub Dispose()
'Dispose of objects in memory
dddevice.Dispose()
psurface.Dispose()
ssurface.Dispose()
StructuresSurface.Dispose()
LevelSurface.Dispose()
clip.Dispose()
End Sub
Private Sub LimitFPS()
'Simple FPS Limiter
thisTick = Environment.TickCount
sinceLastTick = thisTick - lastTick
lastTick = thisTick
If sinceLastTick < (1000 / fps) Then
System.Threading.Thread.Sleep((1000 / fps) - sinceLastTick)
End If
End Sub
The error i get is when i try and draw the structuresurface to the back buffer simply points out the line it occured on (highlighted in red)
Can someone tell me where i'm going wrong?
Do i need to set some kind of property on the surface?