Table of Contents

Class Tilemap

Namespace
PopcorningGuineaPig.Engine.Gameplay
Assembly
PopcorningGuineaPig.Engine.dll

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

width int

Width in tiles

height int

Height in tiles

tileWidth int

Width of each tile in pixels

tileHeight int

Height of each tile in pixels

Properties

Height

public int Height { get; set; }

Property Value

int

Layers

public List<TilemapLayer> Layers { get; set; }

Property Value

List<TilemapLayer>

Name

public string Name { get; set; }

Property Value

string

Properties

public Dictionary<string, string> Properties { get; set; }

Property Value

Dictionary<string, string>

TileHeight

public int TileHeight { get; set; }

Property Value

int

TileSize

public Vector2 TileSize { get; }

Property Value

Vector2

TileWidth

public int TileWidth { get; set; }

Property Value

int

Tilesets

public List<Tileset> Tilesets { get; set; }

Property Value

List<Tileset>

Width

public int Width { get; set; }

Property Value

int

WorldSize

public Vector2 WorldSize { get; }

Property Value

Vector2

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

layerIndex int

Index of the layer to convert

gridOrigin Vector3

Origin 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

globalId int

Global tile ID from the tilemap

tileset Tileset

Tileset containing the tile

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

layerIndex int

Layer index

x int

X coordinate in tiles

y int

Y coordinate in tiles

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

tileId int

Global 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

tilePosition Vector2

Tile 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

worldPosition Vector2

World position

Returns

Vector2

Tile coordinates