Skip to content

NodePool

Nodes made by a factory once and used again: get() gives a free one (or makes one), release() takes it back. From nodePool(factory, options).

const labels = nodePool(() => engine.text('', { size: 32, outline: true }), { max: 20 })
const l = hud.add(labels.get({ x, y, text: '+10' }))
engine.tween(l, { y: y - 60, alpha: 0 }, 0.8).then(() => labels.release(l))

T extends Node

new NodePool<T>(factory, opts?): NodePool<T>

Use nodePool(factory, options).

() => T

NodePoolOptions<T>

NodePool<T>

readonly stats: NodePoolStats

live, free and created: kept up to date (one object, read it any time).

get(props?): T

A node: a free one, back to how the factory made it, or a new one; then props are applied (any node field, and a text’s text). It is not added anywhere: add it to a group.

What is reset: position, rotation, scale, alpha, visible, blend, tint, z, anchor, hitRadius, clip, mask, filters (the same objects the factory set, not copies); a sprite’s frame, size and slice; a shape’s spec; a text’s string and style; an animation’s fps, loop, speed, onComplete and playing, rewound to its first frame. Not reset: data, a group’s children, and nodes’ own fields in your subclasses: reset those in options.reset.

NodeProps & object

T


release(node): void

Takes a node back: out of its group, hidden, its tweens stopped (they resolve), its animation stopped, reset; not destroyed. Keep no reference to it: the next get() gives it to someone else. Past max free nodes, it is destroyed instead. Releasing a node twice, or one of another pool, does nothing (and says so once).

T

void


clear(): void

Destroys the free nodes (the ones in use stay).

void


destroy(): void

Destroys every node it made, in use or free; get() can’t be called after.

void