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
static SCENE_CELL_SIZE = 256
hash2D

The spatial-hash object used by this system.

hashTargets
boolean
skipBoundsUpdate = false

Whether the bounds should be recalculated whenever update is invoked.

update

Updates the spatial-hash for the whole scene graph.

boolean
updateBeforeRender = true
updateTicker = undefined

The ticker on which the spatial hash is being updated.

Methods from SpatialHashSystem

this
addTarget(displayObject: PIXI.DisplayObject)

Adds the display-object to the hash-targets list. It will be updated in the spatial-hash on each tick.

void
prerender()

Prerender event handler. This will invoke update if updateBeforeRender is enabled.

this
removeTarget(displayObject: PIXI.DisplayObject)

Removes the display-object from the hash-targets list.

Set<PIXI.DisplayObject>
search(objectOrBounds: PIXI.Rectangle | PIXI.DisplayObject)
this
setTicker(ticker: PIXI.Ticker)

Sets the ticker on which the spatial hash is updated.

void
protected updateRecursive(displayObject: PIXI.DisplayObject)

Puts the display-object and its subtree into the spatial hash.

Public Properties


SCENE_CELL_SIZE SpatialHashSystem.ts:216
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).

hash2D SpatialHashSystem.ts:57
hash2D

The spatial-hash object used by this system.

hashTargets SpatialHashSystem.ts:62
hashTargets

The display-object which are updated in the spatial hash on each frame, including all their direct and indirect children.

skipBoundsUpdate SpatialHashSystem.ts:79
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 SpatialHashSystem.ts:168
update

Updates the spatial-hash for the whole scene graph.

If updateBeforeRender is enabled, this will be invoked on each render call.

updateBeforeRender SpatialHashSystem.ts:68
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 SpatialHashSystem.ts:74
updateTicker = undefined

The ticker on which the spatial hash is being updated.

Public Methods


addTarget SpatialHashSystem.ts:89
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.

Parameters:
Name Type Description
displayObject PIXI.DisplayObject
Returns:
Type Description
this
prerender SpatialHashSystem.ts:131
prerender() → {void}

Prerender event handler. This will invoke update if updateBeforeRender is enabled.

Returns:
Type Description
void
removeTarget SpatialHashSystem.ts:101
removeTarget(displayObject: PIXI.DisplayObject) → {this}

Removes the display-object from the hash-targets list.

Parameters:
Name Type Description
displayObject PIXI.DisplayObject
Returns:
Type Description
this
setTicker SpatialHashSystem.ts:142
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.

Parameters:
Name Type Description
ticker PIXI.Ticker
Returns:
Type Description
this

Protected Methods


updateRecursive SpatialHashSystem.ts:194
protected updateRecursive(displayObject: PIXI.DisplayObject) → {void}

Puts the display-object and its subtree into the spatial hash.

Parameters:
Name Type Description
displayObject PIXI.DisplayObject
Returns:
Type Description
void

Powered by webdoc!