Class Tilemap
Represents a complete tilemap loaded from a TMX file. Contains multiple layers, tilesets, and provides rendering capabilities.
public class Tilemap
- Inheritance
-
Tilemap
- Inherited Members
Constructors
Tilemap(int, int, int, int)
Creates an empty tilemap with specified dimensions.
public Tilemap(int width, int height, int tileWidth, int tileHeight)
Parameters
widthintWidth in tiles
heightintHeight in tiles
tileWidthintWidth of each tile in pixels
tileHeightintHeight of each tile in pixels
Properties
Height
public int Height { get; set; }
Property Value
Layers
public List<TilemapLayer> Layers { get; set; }
Property Value
Name
public string Name { get; set; }
Property Value
Properties
public Dictionary<string, string> Properties { get; set; }
Property Value
TileHeight
public int TileHeight { get; set; }
Property Value
TileSize
public Vector2 TileSize { get; }
Property Value
TileWidth
public int TileWidth { get; set; }
Property Value
Tilesets
public List<Tileset> Tilesets { get; set; }
Property Value
Width
public int Width { get; set; }
Property Value
WorldSize
public Vector2 WorldSize { get; }
Property Value
Methods
CreateTileGridFromLayer(int, Vector3)
Creates a TileGrid from a specific tilemap layer for collision detection and game logic.
public TileGrid? CreateTileGridFromLayer(int layerIndex, Vector3 gridOrigin = default)
Parameters
layerIndexintIndex of the layer to convert
gridOriginVector3Origin point for the tile grid in 3D space
Returns
- TileGrid
TileGrid populated with tiles from the tilemap layer
GetLocalTileId(int, Tileset)
Converts a global tile ID to a local tileset tile ID.
public int GetLocalTileId(int globalId, Tileset tileset)
Parameters
Returns
- int
Local tile ID within the tileset
GetTileId(int, int, int)
Gets the tile ID at the specified grid coordinates in a specific layer.
public int GetTileId(int layerIndex, int x, int y)
Parameters
Returns
- int
Tile ID, or 0 if empty or out of bounds
GetTilesetForTile(int)
Gets the tileset that contains the specified tile ID.
public Tileset? GetTilesetForTile(int tileId)
Parameters
tileIdintGlobal tile ID
Returns
- Tileset
Tileset containing the tile, or null if not found
GetWorldBounds()
Gets the bounds of the tilemap in world coordinates.
public Rectangle GetWorldBounds()
Returns
- Rectangle
Rectangle representing the tilemap bounds
TileToWorld(Vector2)
Converts tile coordinates to world coordinates (top-left of tile).
public Vector2 TileToWorld(Vector2 tilePosition)
Parameters
tilePositionVector2Tile coordinates
Returns
- Vector2
World position
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
WorldToTile(Vector2)
Converts world coordinates to tile coordinates.
public Vector2 WorldToTile(Vector2 worldPosition)
Parameters
worldPositionVector2World position
Returns
- Vector2
Tile coordinates