ReferenceBehaviorsInterface
BehaviorObject
A behavior with an optional setup step for each particle.
A behavior that can also perform initialization when the particle is spawned.
To remember something per particle, create a WeakMap keyed by particle inside your behavior’s factory function, so that every instance of the behavior gets its own map.
Example
Section titled “Example”const shrink = (): Behavior => { const startSize = new WeakMap<Particle, number>(); return { init(particle) { startSize.set(particle, particle.size); }, update(particle) { const start = startSize.get(particle) as number; particle.size = start * (1 - particle.age / particle.lifetime); }, };};Properties
Section titled “Properties”initoptionalBehaviorInitThe initialization function of the behavior, called once for each particle, right after it spawns.
updateBehaviorUpdateThe update function of the behavior, called on every particle every simulation step.