Class Tilemap
Represents a complete tilemap loaded from a TMX file. Contains multiple layers, tilesets, and provides rendering capabilities.
Inherited Members
Namespace: PopcorningGuineaPig.Engine.Gameplay
Assembly: PopcorningGuineaPig.Engine.dll
Syntax
public class Tilemap
Constructors
| Edit this page View SourceTilemap(int, int, int, int)
Creates an empty tilemap with specified dimensions.
Declaration
public Tilemap(int width, int height, int tileWidth, int tileHeight)
Parameters
| Type | Name | Description |
|---|---|---|
| int | width | Width in tiles |
| int | height | Height in tiles |
| int | tileWidth | Width of each tile in pixels |
| int | tileHeight | Height of each tile in pixels |
Properties
| Edit this page View SourceHeight
Declaration
public int Height { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Layers
Declaration
public List<TilemapLayer> Layers { get; set; }
Property Value
| Type | Description |
|---|---|
| List<TilemapLayer> |
Name
Declaration
public string Name { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Properties
Declaration
public Dictionary<string, string> Properties { get; set; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, string> |
TileHeight
Declaration
public int TileHeight { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
TileSize
Declaration
public Vector2 TileSize { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
TileWidth
Declaration
public int TileWidth { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
Tilesets
Declaration
public List<Tileset> Tilesets { get; set; }
Property Value
| Type | Description |
|---|---|
| List<Tileset> |
Width
Declaration
public int Width { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
WorldSize
Declaration
public Vector2 WorldSize { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 |
Methods
| Edit this page View SourceCreateTileGridFromLayer(int, Vector3)
Creates a TileGrid from a specific tilemap layer for collision detection and game logic.
Declaration
public TileGrid? CreateTileGridFromLayer(int layerIndex, Vector3 gridOrigin = default)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerIndex | Index of the layer to convert |
| Vector3 | gridOrigin | Origin point for the tile grid in 3D space |
Returns
| Type | Description |
|---|---|
| TileGrid | TileGrid populated with tiles from the tilemap layer |
GetLocalTileId(int, Tileset)
Converts a global tile ID to a local tileset tile ID.
Declaration
public int GetLocalTileId(int globalId, Tileset tileset)
Parameters
| Type | Name | Description |
|---|---|---|
| int | globalId | Global tile ID from the tilemap |
| Tileset | tileset | Tileset containing the tile |
Returns
| Type | Description |
|---|---|
| int | Local tile ID within the tileset |
GetTileId(int, int, int)
Gets the tile ID at the specified grid coordinates in a specific layer.
Declaration
public int GetTileId(int layerIndex, int x, int y)
Parameters
| Type | Name | Description |
|---|---|---|
| int | layerIndex | Layer index |
| int | x | X coordinate in tiles |
| int | y | Y coordinate in tiles |
Returns
| Type | Description |
|---|---|
| int | Tile ID, or 0 if empty or out of bounds |
GetTilesetForTile(int)
Gets the tileset that contains the specified tile ID.
Declaration
public Tileset? GetTilesetForTile(int tileId)
Parameters
| Type | Name | Description |
|---|---|---|
| int | tileId | Global tile ID |
Returns
| Type | Description |
|---|---|
| Tileset | Tileset containing the tile, or null if not found |
GetWorldBounds()
Gets the bounds of the tilemap in world coordinates.
Declaration
public Rectangle GetWorldBounds()
Returns
| Type | Description |
|---|---|
| Rectangle | Rectangle representing the tilemap bounds |
TileToWorld(Vector2)
Converts tile coordinates to world coordinates (top-left of tile).
Declaration
public Vector2 TileToWorld(Vector2 tilePosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | tilePosition | Tile coordinates |
Returns
| Type | Description |
|---|---|
| Vector2 | World position |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string that represents the current object. |
Overrides
| Edit this page View SourceWorldToTile(Vector2)
Converts world coordinates to tile coordinates.
Declaration
public Vector2 WorldToTile(Vector2 worldPosition)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | worldPosition | World position |
Returns
| Type | Description |
|---|---|
| Vector2 | Tile coordinates |