Time for action – drawing the tile map
Add the
Draw()
method to the TileMap class:#region Drawing static public void Draw(SpriteBatch spriteBatch) { int startX = GetSquareByPixelX((int)Camera.Position.X); int endX = GetSquareByPixelX((int)Camera.Position.X + Camera.ViewPortWidth); int startY = GetSquareByPixelY((int)Camera.Position.Y); int endY = GetSquareByPixelY((int)Camera.Position.Y + Camera.ViewPortHeight); for (int x = startX; x <= endX; x++) for (int y = startY; y <= endY; y++) { if ((x >= 0) && (y >= 0) && (x < MapWidth) && (y < MapHeight)) { spriteBatch.Draw( texture, SquareScreenRectangle(x, y), tiles[GetTileAtSquare(x,y)], Color.White); } } } #endregion
In the
LoadContent()
method of theGame1.cs
file, initialize the TileMap...