Constructor
new PathFinder(source)
Parameters:
| Name | Type | Description |
|---|---|---|
source | TileCollisionLayer | | Either a TileCollisionLayer (size and walkability auto-derived) or a Vector2 grid size (user overrides isWalkable). |
- Source
Example
// Tile-layer driven (most common):
const pf = new PathFinder(myTileCollisionLayer);
const path = pf.findPath(player.pos, mousePos);
// Bare grid with custom walkability:
const pf = new PathFinder(vec2(50, 50));
pf.isWalkable = (x, y) => myGrid[y*50 + x] === 0;Methods
getCost(x, y) → {number}
Default extra cost for stepping on a cell. Returns 0 (free) by default. Override to add cost-weighted terrain (mud, swamp, etc).
Parameters:
| Name | Type | Description |
|---|---|---|
x | number | Tile x |
y | number | Tile y |
- Source
Returns:
- Type:
- number
getNode(x, y) → {PathFinderNode|null}
Get the node at tile coords, or null if out of bounds.
Parameters:
| Name | Type | Description |
|---|---|---|
x | number | |
y | number |
- Source
Returns:
- Type:
- PathFinderNode |
null
isWalkable(x, y) → {boolean}
Default walkability: if a tile layer was provided, returns true when the cell has no solid collision data; otherwise returns true. Override on the instance or via a subclass.
Parameters:
| Name | Type | Description |
|---|---|---|
x | number | Tile x |
y | number | Tile y |
- Source
Returns:
- Type:
- boolean