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).
Example
Section titled “Example”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))Type Parameters
Section titled “Type Parameters”T extends Node
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new NodePool<
T>(factory,opts?):NodePool<T>
Use nodePool(factory, options).
Parameters
Section titled “Parameters”factory
Section titled “factory”() => T
Returns
Section titled “Returns”NodePool<T>
Properties
Section titled “Properties”
readonlystats:NodePoolStats
live, free and created: kept up to date (one object, read it any time).
Methods
Section titled “Methods”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.
Parameters
Section titled “Parameters”props?
Section titled “props?”NodeProps & object
Returns
Section titled “Returns”T
release()
Section titled “release()”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).
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”void
clear()
Section titled “clear()”clear():
void
Destroys the free nodes (the ones in use stay).
Returns
Section titled “Returns”void
destroy()
Section titled “destroy()”destroy():
void
Destroys every node it made, in use or free; get() can’t be called after.
Returns
Section titled “Returns”void