Skip to content

Tilemap

A spawned Tiled map: its size, tile entities by layer, objects, and lookups for collision and grid logic.

cols: number

Map size in cells.


height: number


layers: Record<string, Entity[]>

Tile entities by layer name. Hidden layers get Position only (handy for collision layers).


objects: TiledObject[]


rows: number


tileHeight: number


tileWidth: number


width: number

Map size in pixels.

cellAt(x, y): object

The grid cell under a world point (it may be outside the map), for pathfinding and grid logic.

number

number

object

col: number

row: number


cellCenter(col, row): object

The world point at the center of a cell (of its diamond on isometric maps): where things standing on it sit.

number

number

object

x: number

y: number


moveAndCollide(e, dx, dy, layer): object

Moves e by (dx, dy) and stops it against the tiles of layer, one axis at a time so it slides along walls, in steps no longer than a tile so fast movers never pass through. Its box is its Sprite box, placed by Anchor. Returns which axes were blocked: const hit = map.moveAndCollide(player, vx * dt, vy * dt, 'walls'), then if (hit.y) vy = 0, and the player stands on ground when that happened while falling. A hidden layer works as an invisible collision layer. Orthogonal maps only.

number

number

number

string

object

x: boolean

y: boolean


tileAt(layer, x, y): number

The tile of layer under a world point, or -1: map.tileAt('walls', x, y + h / 2) >= 0 tests a character’s feet. Isometric maps test the cell’s diamond, not the (taller) tile image. Despawned tiles read as -1.

string

number

number

number