new Grid(width, height, [matrix])
The Grid class, which serves as the encapsulation of the layout of the nodes on the map.
- Source:
- ./src/core/Grid.js, line 11
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
width |
number | Number of columns of the grid. | |
height |
number | Number of rows of the grid. | |
matrix |
Array.<Array.<(number | boolean)>> |
<optional> |
A 0-1 matrix representing the walkable status of the nodes(0 or false for walkable). If the matrix is not supplied, all the nodes will be walkable. |
Properties
-
height :number
-
The number of rows of the grid.
- Source:
- ./src/core/Grid.js, line 21
-
width :number
-
The number of columns of the grid.
- Source:
- ./src/core/Grid.js, line 16
Methods
-
<private> _buildGrid([matrix])
-
Build the grids.
- Source:
- ./src/core/Grid.js, line 35
- See:
Parameters:
Name Type Argument Description matrix
Array.<Array.<number | boolean>> <optional>
A 0-1 matrix representing the walkable status of the nodes. -
getAttributeAt(x, y, attr)
-
Generic getter of the attribute at the given position. Note: This method gets the same result as: {@code node = grid.getNodeAt(x, y); return node[attr];}
- Source:
- ./src/core/Grid.js, line 140
Parameters:
Name Type Description x
number The x coordinate of the position. y
number The y coordinate of the position. attr
string The name of attribute to get. Returns:
The value of the attribute. -
getNodeAt(x, y) → {PF.Node}
-
Get the node at the given position.
- Source:
- ./src/core/Grid.js, line 78
Parameters:
Name Type Description x
number The x coordinate of the node. y
number The y coordinate of the node. Returns:
- Type
- PF.Node
-
isInside(x, y) → {boolean}
-
Determine whether the given position is inside the grid.
- Source:
- ./src/core/Grid.js, line 111
Parameters:
Name Type Description x
number The x coordinate of the position. y
number The y coordinate of the position. Returns:
Whether the position is inside.- Type
- boolean
-
isWalkableAt(x, y) → {boolean}
-
Determine whether the node on the given position is walkable.
- Source:
- ./src/core/Grid.js, line 89
Parameters:
Name Type Description x
number The x coordinate of the node. y
number The y coordinate of the node. Returns:
- The walkability of the node.- Type
- boolean
-
setAttributeAt(x, y, attr, value)
-
Generic setter of the attribute at the given position. Note: This method gets the same result as: {@code node = grid.getNodeAt(x, y); node[attr] = value;}
- Source:
- ./src/core/Grid.js, line 126
Parameters:
Name Type Description x
number The x coordinate of the position. y
number The y coordinate of the position. attr
string The name of attribute to set. value
* The value of attribute. -
setWalkableAt(x, y, walkable)
-
Set whether the node on the given position is walkable.
- Source:
- ./src/core/Grid.js, line 100
Parameters:
Name Type Description x
number The x coordinate of the node. y
number The y coordinate of the node. walkable
boolean Whether the position is walkable.