The TilemapRenderer component renders 2D tile-based maps to the screen.
It uses a tileset image as a source for individual tiles, which are arranged according to a provided array of tile IDs.
The component supports features like tinting, masking, opacity control, and custom tile dimensions.
Maps can be rendered in chunks for improved performance with large tilemaps, and tiles can be assigned to specific render layers.
Each tile is referenced by an ID, with 0 representing empty space.

const tilemapRenderer = new TilemapRenderer({
layer: "Default",
tileset: {
image: this.assetManager.getImage("tileset.png"),
width: 10,
tileWidth: 32,
tileHeight: 32,
margin: new Vector2(0, 0),
spacing: new Vector2(0, 0)
},
data: [1, 2, 3, 4],
chunks: [],
width: 2,
height: 2,
tileWidth: 32,
tileHeight: 32,
tintColor: "#FFFFFF",
maskColor: "#FF0000",
maskColorMix: 0,
opacity: 1,
smooth: false
});

Constructors

Properties

chunks: Chunk[] = []

Array of tile data split into chunks

data: number[] = []

Array of tiles. ID 0 (zero) represents empty space.

height: number = 0

The height of the tilemap (in tiles)

layer: string = defaultRenderLayer

The render layer

maskColor: string

Define a mask color for the image

maskColorMix: number

Define the opacity of the mask color between 1 and 0

opacity: number = 1

Change the opacity between 1 and 0

smooth: boolean = false

TRUE for smooth pixels (not recommended for pixel art)

tileHeight: number = undefined

The height of the tile to render

tileset: Tileset = undefined

The Tileset instance

tileWidth: number = undefined

The width of the tile to render

tintColor: string = undefined

Define a color for tinting the tiles

width: number = 0

The width of the tilemap (in tiles)