Grid

PhaserPathfinding. Grid

The grid class is used to create a grid that the pathfinding algorithm can use

Constructor

new Grid(sizeX, sizeY, walkableLayerIndex)

Parameters:
Name Type Description
sizeX number

The width of the grid in tile units

sizeY number

The height of the grid in tile units

walkableLayerIndex number
Source:

Methods

cloneMatrix() → {Array.<Array.<Node>>}

Clones the matrix of nodes, used internally by the pathfinding algorithm to avoid modifying the original grid when calculating costs

Source:

getNode(x, y, matrixopt) → (nullable) {Node}

Gets a node from the grid at a specific position in tile units or undefined if the position is not in the grid

Parameters:
Name Type Attributes Default Description
x number

The x position in tile units

y number

The y position in tile units

matrix Array.<Array.<Node>> <optional>
default

The matrix to get the node from, default is the current one

Source:

getTilePositionInWorld(position) → (nullable) {Phaser.Math.Vector2}

Gets the position in tile units from the position in pixels or undefined if the position is not in the walkable grid

Parameters:
Name Type Description
position Phaser.Math.Vector2

The position in pixels

Source:

getWorldPositionFromNode(node) → (nullable) {Phaser.Math.Vector2}

Gets the position in pixels for a specific node

Parameters:
Name Type Description
node Node

The node to get the position from

Source:

(static) createFromMap(map, obstacles, walkableLayerIndexopt) → {Grid}

Creates a new grid from a tilemap

Parameters:
Name Type Attributes Default Description
map Phaser.Tilemaps.Tilemap

The tilemap to create the grid from

obstacles Array.<Phaser.Tilemaps.TilemapLayer>

An array of tilemap layers that are considered as obstacles

walkableLayerIndex number <optional>
0

The layer index that is considered as walkable Default: 0

Source: