Time for action – the TileMap class – part 3

  1. Add the Draw() method to the TileMap class:
    #region Drawing static public void Draw(SpriteBatch spriteBatch) { int startX = GetCellByPixelX((int)Camera.Position.X); int endX = GetCellByPixelX((int)Camera.Position.X + Camera.ViewPortWidth); int startY = GetCellByPixelY((int)Camera.Position.Y); int endY = GetCellByPixelY((int)Camera.Position.Y + Camera.ViewPortHeight); for (int x = startX; x <= endX; x++) for (int y = startY; y <= endY; y++) { for (int z = 0; z < MapLayers; z++) { if ((x >= 0) && (y >= 0) && (x < MapWidth) && (y < MapHeight)) { spriteBatch.Draw( tileSheet, CellScreenRectangle(x,y), TileSourceRectangle(mapCells[x,y].LayerTiles[z]), Color.White, 0.0f, Vector2.Zero, SpriteEffects.None, 1f ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.