new Tilemap()
Tilemap component renders a grid of tiles from a tileset.
- Source
Extends
Classes
Members
pixelHeight
Get pixel height of the tilemap.
- Source
pixelWidth
Get pixel width of the tilemap.
- Source
(readonly) properties
The entity that this component is attached to.
- Inherited From
- Source
Methods
addLayer()
Register another traversable map layer, ordered by render order then insertion.
- Source
deserialize(props)
Populates the component properties from a data object. Override this method for custom property handling.
| Name | Type | Description |
|---|---|---|
props | object | The properties object (usually from JSON). |
- Inherited From
- Source
draw(ctx, offsetX, offsetY)
Draw the tilemap.
| Name | Type | Default | Description |
|---|---|---|---|
ctx | CanvasRenderingContext2D | ||
offsetX | number | 0 | Camera offset X. |
offsetY | number | 0 | Camera offset Y. |
- Source
findPath()
Deterministic minimum-cost four-way path; returns coordinates excluding start, or null.
- Source
getCellMetadata()
Return a defensive copy of cell metadata, or null when unset/out of bounds.
- Source
getResolvedMetadata()
Resolve tile defaults with cell-specific metadata taking precedence.
- Source
getTile(x, y) → {number}
Get a tile at position.
| Name | Type | Description |
|---|---|---|
x | number | X position in tiles. |
y | number | Y position in tiles. |
- Source
Tile ID or -1 if empty/out of bounds.
- Type:
- number
getTileMetadata()
Return a defensive copy of metadata for a tile ID, or null when unset.
- Source
gridIndex()
Convert tile coordinates to a stable row-major grid index, or null out of bounds.
- Source
isSolid(x, y) → {boolean}
Check if a tile is solid (non-empty).
| Name | Type | Description |
|---|---|---|
x | number | |
y | number |
- Source
- Type:
- boolean
loadFromArray(data)
Load tilemap from 2D array.
| Name | Type | Description |
|---|---|---|
data | Array.<Array.<number>> | 2D array of tile IDs. |
- Source
moveOccupant()
Move an occupied actor by one cardinal tile, leaving state unchanged on failure.
- Source
moveOccupantToward()
Follow a shortest path by one step toward a destination; returns the new cell or null.
- Source
occupy()
Place or move an occupant; each occupant may occupy only one cell.
- Source
setCellMetadata()
Set validated metadata for one row-major cell, overriding tile defaults.
- Source
setTile(x, y, tileId)
Set a tile at position.
| Name | Type | Description |
|---|---|---|
x | number | X position in tiles. |
y | number | Y position in tiles. |
tileId | number | Tile ID from tileset (-1 for empty). |
- Source
setTileMetadata()
Set validated gameplay metadata for a tile ID.
- Source
worldToTile(worldX, worldY) → {Object}
Convert world position to tile position.
| Name | Type | Description |
|---|---|---|
worldX | number | |
worldY | number |
- Source
- Type:
- Object