TilemapRenderer

The TilemapRenderer component renders a tile-based map. It uses a tileset image as the source for individual tiles, arranged according to an array of tile IDs. It uses the entity’s Transform for position. See Rendering for an overview.

Each tile is referenced by an ID, where 0 represents empty space. The tile data can be provided directly, or populated from a Tiled map with the TiledWrapper component.

Options

OptionTypeDefaultDescription
tilesetTilesetThe tileset that provides the tiles (see below).
datanumber[][]Array of tile IDs. 0 is empty space.
chunksChunk[][]Tile data split into chunks, for large maps.
widthnumber0Map width in tiles.
heightnumber0Map height in tiles.
tileWidthnumberRendered tile width.
tileHeightnumberRendered tile height.
layerstring"Default"The render layer.
opacitynumber1Opacity between 0 and 1.
tintColorstringColor used to tint the tiles.
maskColorstringMask color applied to the tiles.
maskColorMixnumberMask color opacity between 0 and 1.
smoothbooleanfalseSmooths pixels. Not recommended for pixel art.

Tileset

FieldTypeDescription
imageHTMLImageElement | stringThe tileset image, or an asset URL/name string.
widthnumberTileset width in tiles.
tileWidthnumberTile width in pixels.
tileHeightnumberTile height in pixels.
marginVector2Optional margin (top and left) in pixels.
spacingVector2Optional spacing (bottom and right) in pixels.

Example

import { Transform, TilemapRenderer } from "angry-pixel";

this.entityManager.createEntity([
    new Transform(),
    new TilemapRenderer({
        layer: "Default",
        tileset: {
            image: this.assetManager.getImage("tileset.png"),
            width: 8,
            tileWidth: 16,
            tileHeight: 16,
        },
        data: [1, 2, 3, 4],
        width: 2,
        height: 2,
    }),
]);