- Psykick2D
CollisionGrid
A simple grid for finding any collisions Best used for tiled game worlds with defined boundaries
new CollisionGrid(
options
)
Parameters
options | object | ||
options.width | number | Width of the game world | |
options.height | number | Height of the game world | |
options.cellWidth | number | Width of a cell. May use cellSize instead | |
options.cellHeight | number | Height of a cell. May use cellSize instead | |
options.cellSize | number | Set this if you want width and height to be the same | |
options.componentType | number | Type of component to treat as a rectangle | 'Rectangle' |
Properties
width | number | ||
height | number | ||
cellWidth | number | ||
cellHeight | number | ||
_grid | Array | private | new Array() |
Methods
addEntity( )
Adds an entity to the grid
Entity must have a Rectangle component
entity | Entity |
removeEntity( )
Removes an entity from the grid
entity | Entity |
moveEntity( )
Moves an Entity and updates it's position in the grid
entity | Entity | ||
deltaPosition |
Entity[] getCollisions( )
Gets the collisions for a given Entity
entity | Entity |