Skip to content

nodePool

const nodePool: <T>(factory, options?) => NodePool<T>

A pool of nodes made by factory and used again: get() a node (a free one, reset to how the factory made it, or a new one), release() it instead of destroying it. Worth it only when spawning many nodes a second; creating and destroying nodes is fine otherwise.

T extends Node

() => T

NodePoolOptions<T>

NodePool<T>

import { nodePool } from '@fabiplay/engine'
const coins = nodePool(() => engine.shape({ type: 'circle', r: 16, fill: '#FBD46A' }), { max: 40 })
const coin = layer.add(coins.get({ x: 200, y: -20 }))
engine.tween(coin, { y: 740 }, 2, 'linear').then(() => coins.release(coin))