SpatialHashSystem
class SpatialHashSystem extends _System
System plugin to the renderer for providing spatial hashing on the whole scene graph.
import { SpatialHashSystem } from "pixi-spatial-hash";
renderer.addSystem(SpatialHashSystem, "spatialHash");
renderer.spatialHash.addTarget(stage);
This system provides a shared spatial hash for the whole scene graph. It is designed to be updated on
each tick. By default, it will update itself before each render (on the prerender
event). This
may cause redundant updates if you render multiple times each tick; in that case, you can custom set a
ticker using SpatialHashSystem#setTicker.
renderer.spatialHash.setTicker(Ticker.shared);
You must register the "stage" as a hash-target in order to add it to the hash.
Summary
Properties from SpatialHashSystem
number |
|
The spatial-hash object used by this system. |
|
|
|
boolean |
Whether the bounds should be recalculated whenever |
Updates the spatial-hash for the whole scene graph. |
|
boolean |
|
The ticker on which the spatial hash is being updated. |
Methods from SpatialHashSystem
this |
Adds the display-object to the hash-targets list. It will be updated in the spatial-hash on each tick. |
void |
Prerender event handler. This will invoke |
this |
Removes the display-object from the hash-targets list. |
Set<PIXI.DisplayObject> |
|
this |
Sets the ticker on which the spatial hash is updated. |
void |
Puts the display-object and its subtree into the spatial hash. |
Public Properties
static SCENE_CELL_SIZE: number = 256
The 2D hashing cell size for the spatial-hash system. This must be set before the renderer is created (or the spatial-hash system is added to the renderer).
hashTargets
The display-object which are updated in the spatial hash on each frame, including all their direct and indirect children.
skipBoundsUpdate: boolean = false
Whether the bounds should be recalculated whenever update
is invoked.
You should turn it off if you can guarantee the bounds are correct when calling update
. This
can be done by adding a high-priority bounds-updating callback on the ticker before the spatial-hash
update callback.
update
Updates the spatial-hash for the whole scene graph.
If updateBeforeRender
is enabled, this will be invoked on each render call.
updateBeforeRender: boolean = true
Whether to update the spatial hash on the prerender event. You should turn this off if invoke render
multiple times on each tick.
updateTicker = undefined
The ticker on which the spatial hash is being updated.
Public Methods
addTarget(displayObject: PIXI.DisplayObject) → {this}
Adds the display-object to the hash-targets list. It will be updated in the spatial-hash on each tick.
Name | Type | Description |
---|---|---|
displayObject | PIXI.DisplayObject |
Type | Description |
---|---|
this |
prerender() → {void}
Prerender event handler. This will invoke update
if updateBeforeRender
is enabled.
Type | Description |
---|---|
void |
removeTarget(displayObject: PIXI.DisplayObject) → {this}
Removes the display-object from the hash-targets list.
Name | Type | Description |
---|---|---|
displayObject | PIXI.DisplayObject |
Type | Description |
---|---|
this |
search(objectOrBounds: PIXI.Rectangle | PIXI.DisplayObject) → {Set<PIXI.DisplayObject>}
Searches for display-objects in the hash that intersect with the given rectangle bounds or that of the display-object passed.
Name | Type | Description |
---|---|---|
objectOrBounds | PIXI.Rectangle | PIXI.DisplayObject |
display-object or a rectangle |
Type | Description |
---|---|
Set<PIXI.DisplayObject> |
setTicker(ticker: PIXI.Ticker) → {this}
Sets the ticker on which the spatial hash is updated.
If a ticker was already set, then the update callback is safely removed. If you want to turn off updating on each tick, then you can pass null as the ticker.
updateBeforeRender
is automatically disable when setting the ticker to a non-null value.
Name | Type | Description |
---|---|---|
ticker | PIXI.Ticker |
Type | Description |
---|---|
this |
Protected Methods
protected updateRecursive(displayObject: PIXI.DisplayObject) → {void}
Puts the display-object and its subtree into the spatial hash.
Name | Type | Description |
---|---|---|
displayObject | PIXI.DisplayObject |
Type | Description |
---|---|
void |