Tilemap
A spawned Tiled map: its size, tile entities by layer, objects, and lookups for collision and grid logic.
Properties
Section titled “Properties”cols:
number
Map size in cells.
height
Section titled “height”height:
number
layers
Section titled “layers”layers:
Record<string,Entity[]>
Tile entities by layer name. Hidden layers get Position only (handy for collision layers).
objects
Section titled “objects”objects:
TiledObject[]
rows:
number
tileHeight
Section titled “tileHeight”tileHeight:
number
tileWidth
Section titled “tileWidth”tileWidth:
number
width:
number
Map size in pixels.
Methods
Section titled “Methods”cellAt()
Section titled “cellAt()”cellAt(
x,y):object
The grid cell under a world point (it may be outside the map), for pathfinding and grid logic.
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”object
col:
number
row:
number
cellCenter()
Section titled “cellCenter()”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.
Parameters
Section titled “Parameters”number
number
Returns
Section titled “Returns”object
x:
number
y:
number
moveAndCollide()
Section titled “moveAndCollide()”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.
Parameters
Section titled “Parameters”number
number
number
string
Returns
Section titled “Returns”object
x:
boolean
y:
boolean
tileAt()
Section titled “tileAt()”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.
Parameters
Section titled “Parameters”string
number
number
Returns
Section titled “Returns”number
