I'm trying to create a map class for a simple 2D game. The map has an array(100,100,5)
of string
, returning the kind of tiles to draw ( with 5 possible layers from 0 to 4) players will move on the 2nd layer, the background of the game is on layer 0)
I'm want a drawMap
sub that I would be able to call as needed. ( not the onPaint
method, because I'm loading the game data map from a binary file, and this game contains the needed coordinates, number of tiles, etc and the array of tiles, so I need to load the map info 1st, then use the draw sub)
I'm struggling right now because only the Tiles(0 to 3, 0 to 1,0) are showing ... while my array is full of tiles !
Heres the code :
Public class Map
inherits Panel
'... properties and stuff ....'
Public Sub New(Optional ByVal mapName As String = "")
G = Me.CreateGraphics()
Me.BorderStyle = Windows.Forms.BorderStyle.Fixed3D
Me.Location = New Point(250, 50)
Load(mapName)
Me.Width = mapSizeX * tileSize
Me.Height = mapSizeY * tileSize
End Sub
Public Sub DrawGraphics(ByVal layer As Integer, ByVal g As System.Drawing.Graphics)
For y As Integer = 0 To Map.mapSizeY - 1
For x As Integer = 0 To Map.mapSizeX - 1
If Not Map.Tile(x, y, layer) = "" Then
GetSourceRect( x, y, layer, Map) 'return rectangle from my spritesheet '
dRect = New Rectangle((x * tileSize), (y * Map.tileSize), tileSize, tileSize)
g.DrawImage(SpriteSheet, dRect, sRect, GraphicsUnit.Pixel)
End If
Next
Next
End Sub
end class
Load(mapname)
deserializes a binary file containing the value for mapSizeX
and mapSizeY
, as well as tileSize
and the Tiles(100,100,5)
array all filled up.
What am I doing wrong at this point ?