Constructor
new PathFinder(source)
| Name | Type | Description |
|---|---|---|
source | TileCollisionLayer | | Either a TileCollisionLayer (size and walkability auto-derived) or a Vector2 grid size (user overrides isWalkable). |
- Source
// 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;Members
debug
Properties| Type | Description |
|---|---|
| boolean | If true, draw debug visualization during findPath |
- Source
debugTime
Properties| Type | Description |
|---|---|
| number | Debug primitive lifetime in seconds (0 disables drawing) |
- Source
heuristicWeight
Properties| Type | Description |
|---|---|
| number | A* heuristic multiplier (1 = admissible, higher = greedier) |
- Source
maxLoop
Properties| Type | Description |
|---|---|
| number | Maximum A* expansions before giving up |
- Source
nodes
Properties| Type | Description |
|---|---|
| Array.<PathFinderNode> | Flat row-major array of size.x*size.y nodes |
- Source
size
Properties| Type | Description |
|---|---|
| Vector2 | Grid dimensions in tiles |
- Source
smoothPath
Properties| Type | Description |
|---|---|
| boolean | If true, post-process paths with two-pass smoothing |
- Source
tileLayer
Properties| Type | Description |
|---|---|
| TileCollisionLayer | | Tile layer driving walkability, if any |
- Source
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).
| Name | Type | Description |
|---|---|---|
x | number | Tile x |
y | number | Tile y |
- Source
- Type:
- number
getNode(x, y) → {PathFinderNode|null}
Get the node at tile coords, or null if out of bounds.
| Name | Type | Description |
|---|---|---|
x | number | |
y | number |
- Source
- 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.
| Name | Type | Description |
|---|---|---|
x | number | Tile x |
y | number | Tile y |
- Source
- Type:
- boolean