Readonlycellhow cells sit in the world
Readonlycolscolumns
when a path may move diagonally
the estimate of the distance left
where a cell's position is, from its corner (the top left of a square, the top of a diamond): the points of a path are cell positions
Readonlyrowsrows
Readonlytilea cell's height, in world units
Readonlytilea cell's width, in world units
where the grid's top left corner is in the world
where the grid's top left corner is in the world
the cell under a world position
in world units
in world units
the cell (x the column, y the row), or null off the grid
make every cell of a rectangle solid or open
the cells, x and y its top left column and row
false to open them
set what entering every cell of a rectangle costs
the cells, x and y its top left column and row
1 or more
Find the cheapest path between two world positions, with what the search found: whether it reached the goal, the path as points and as cells, its cost and how much it looked at.
where to start, in world units: a renderable's pos, a
Vector2d, any { x, y }. Clamped to the grid; the start may stand on
a solid cell.
where to go, in world units. Clamped to the grid.
see PathOptions; avoid is in world units
the path, with whether it reaches the goal
The cheapest path between two cells, as cells, from the start to the
goal. Empty when there is none, unless allowPartialPath.
the start cell (x the column, y the row; a fraction
is rounded down). Clamped to the grid.
the goal cell. Clamped to the grid.
allowPartialPath, or the search's options
the cells, start and goal included
The cheapest path between two cells, as points in world units (each
cell's position, see Grid#offset), from the start to the goal.
Empty when there is none, unless allowPartialPath.
the start cell (x the column, y the row; a fraction
is rounded down). Clamped to the grid.
the goal cell. Clamped to the grid.
allowPartialPath, or the search's options
the points, start and goal included
a cell's position in the world: its corner (the top left of a square, the top of a diamond) plus Grid#offset
the cell's column
the cell's row
a vector to set instead of a new one, to allocate nothing
the point, in world units
what entering a cell costs
the cell's column
the cell's row
its weight, 1 or more
whether a cell is on the grid
the cell's column
the cell's row
true if it is
whether a cell is solid (off the grid, it is)
the cell's column
the cell's row
true if it is
Whether a straight line from the centre of one cell to the centre of another crosses only open cells, the two ends included, never cutting a corner between two solid ones.
one end (x the column, y the row)
the other end
only through cells this heavy or lighter
true if the line is clear
Read every cell again from the solid and weight the grid was built
with: after the map changed in a way the grid did not see. Undoes
Grid#setSolid and Grid#setWeight.
read one cell again, as Grid#refresh does every cell
the cell's column
the cell's row
make a cell solid or open: a door, a wall knocked down, a floor fallen away
the cell's column
the cell's row
false to open it
set what entering a cell costs: 1 or more, a finite number (mud 3, a road 1). To block it, use Grid#setSolid.
the cell's column
the cell's row
1 or more
StaticfromA grid over a level's collision shapes: the walls drawn in a Tiled
map's collision layer, or any static body. A cell is solid when a
wall's shape covers any of nine points spread over it (a wall thinner
than an eighth of a cell can slip between them). Cells are read from
the shapes themselves, from the body or the bodyDef, and from each
wall's bounding box when it has none.
Build it once the level is loaded (the shapes are scanned then, not found by a physics query, so it works before the world first steps); Grid#refresh scans them again.
where to look for the walls, its children's
children included (usually app.world)
the grid's size, and which renderables are walls
the grid
StaticfromA grid over a Tiled tile layer: one cell per tile, square on an
orthogonal map and diamonds on an isometric one (staggered and
hexagonal maps throw a RangeError). By default a cell
holding a tile is solid and an empty one is open (a layer of walls);
pass solid to decide from the tile instead (a tile property, its
id). A tile's weight property sets what crossing it costs.
The layer is read again on Grid#refresh, so after changing
tiles with setTile / clearTile, refresh the grid (or just the
changed cell, with Grid#refreshCell).
the tile layer, once its level is loaded
how to read it
a grid with one cell per tile
A grid of cells a path can be found across, with A*.
Each cell is open or solid and has a weight (1 or more) to enter. Build one from a Tiled tile layer (Grid.fromTileLayer), from a level's collision shapes (Grid.fromBodies), or from your own callbacks; change cells as the game goes on with Grid#setSolid and Grid#setWeight, and search it by cell with Grid#getIdPath and Grid#getPointPath, or by world position with Grid#findPath.
Cells are
Vector2ds,xthe column andythe row. Points in world units are each cell's position: its corner plus Grid#offset, which is its centre by default.Cells are square (an orthogonal map) or diamonds (an isometric map), see CellShape. Staggered and hexagonal maps are not supported.
Example