tilemap
A grid of tiles from one tileset asset, centred on the node. cells holds rows of tile ids, or names the .cells file holding them; pixels_per_unit is tile…
On this page
2d · render · 9 properties · 2D
A grid of tiles from one tileset asset, centred on the node. cells holds rows of tile ids, or names the .cells file holding them; pixels_per_unit is tile pixels per world unit.
In a scene, tilemap is the node key that applies it. A script reaches each property below as a field on node.tilemap: reading one asks the running component, and assigning one leaves the rest alone. The whole table is node.tilemap.get() and node.tilemap.set(table).
Properties
| property | type | default | description |
|---|---|---|---|
cells |
variant | {"kind":"inline","rows":[]} |
The tile ids: rows of them in the scene, or a .cells file holding them, for a level too big to read in a scene |
color |
color | [1,1,1,1] |
Tint over every tile, as channel floats or #rrggbb / #rrggbbaa |
flags |
list | [] |
How each cell is turned, as rows of numbers beside the cells: 1 mirrors it left to right, 2 top to bottom, 4 across its diagonal |
material |
asset · material |
— | The material the whole map draws with; empty draws with the built-in one |
origin |
vec2 | [0,0] |
The column and row of the first cell: a map grows in any direction by moving this, and cell 0,0 always has its top-left corner on the node |
pixels_per_unit |
float | 100 |
Tile-texture pixels per world unit At least 0.01. |
seed |
int | 0 |
Which way the variation falls where a rule offers alternates; the same seed lays a map out the same way every time At least 0. |
terrain |
list | [] |
What was painted, as rows of terrain values, -1 where nothing was, when the map autotiles: the cells are resolved from this through the tileset's rules |
tileset |
asset · tileset |
— | The tileset naming the texture and tile grid |
Asset types this component references: material, tileset.
Script functions
Methods of node.tilemap, the handle a node carrying this component exposes. Every handle also has get(), set(table), patch(table), has() and remove().
From render:
| method | what it does |
|---|---|
cell(int, int) -> int |
The tile at a column and row, or -1 for an empty cell or one past the edge. |
set_cell(int, int, int) |
Put one tile at a column and row; a tile below zero clears the cell, and a cell outside the map grows it in that direction. The mesh rebuilds on the next frame. |
set_terrain(int, int, int) |
Paint a terrain value at a column and row and let the tileset's rules pick the tiles, for that cell and the ring around it; below zero clears it. |
terrain(int, int) -> int |
The terrain value painted at a column and row, or -1 where nothing was painted. |
tile_data(int, int) -> any |
What the tileset says about the tile at a column and row -- its [tiles.<id>.data] table -- or nil where the cell is empty or the tile carries none. |