PIXI.SpatialHash
class SpatialHash
2D spatial hashing implementation that provides a mechanism to quickly searching objects intersecting a rectangle.
The spatial hash divides the world space into square "cell" or "buckets". Each display-object added is tracked by which cells they intersect with.
Constructor
new PIXI.SpatialHash(cellSize: number) → {}
| Name | Type | Default | Description |
|---|---|---|---|
| cellSize | number | 256 |
the size of the 2D cells in the hash |
Summary
Methods from SpatialHash
| this |
Puts the display-object into the hash. |
| void |
Removes the display-object from the hash. |
| void |
Reset and clear the spatial hash. |
| Set<Node> |
Searches for all the display-objects that intersect with the given rectangle bounds. |
| void |
|
Public Methods
put(object: Node, bounds) → {this}
Puts the display-object into the hash.
| Name | Type | Description |
|---|---|---|
| object | Node | |
| bounds |
the bounds of the object. This is automatically calculated using |
| Type | Description |
|---|---|
| this |
remove(object: Node) → {void}
Removes the display-object from the hash.
| Name | Type | Description |
|---|---|---|
| object | Node |
| Type | Description |
|---|---|
| void |
reset() → {void}
Reset and clear the spatial hash.
| Type | Description |
|---|---|
| void |
search(bounds: PIXI.Rectangle) → {Set<Node>}
Searches for all the display-objects that intersect with the given rectangle bounds.
| Name | Type | Description |
|---|---|---|
| bounds | PIXI.Rectangle |
| Type | Description |
|---|---|
| Set<Node> |
update(object: Node, bounds) → {void}
Updates this spatial hash to account for any changes in the display-object's bounds. This is equivalent to removing & then adding the object again.
| Name | Type | Description |
|---|---|---|
| object | Node | |
| bounds |
| Type | Description |
|---|---|
| void |