Time for action – handling tiles

  1. Add methods to the TileMap class that relate to reading and setting the tile index associated with individual map squares:
    #region Information about Map Tiles static public int GetTileAtSquare(int tileX, int tileY) { if ((tileX >= 0) && (tileX < MapWidth) && (tileY >= 0) && (tileY < MapHeight)) { return mapSquares[tileX, tileY]; } else { return -1; } } static public void SetTileAtSquare(int tileX, int tileY, int tile) { if ((tileX >= 0) && (tileX < MapWidth) && (tileY >= 0) && (tileY < MapHeight)) { mapSquares[tileX, tileY] = tile; } } static public int GetTileAtPixel(int pixelX, int pixelY) { return GetTileAtSquare( GetSquareByPixelX(pixelX), GetSquareByPixelY(pixelY)); } static public int GetTileAtPixel(Vector2 ...

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.