Skip to main content

Particle emitter

ParticleEmitterBehavior plays a ParticleEffectDefinition on an entity—typically built from particlePresets or particleEffect. A stage system instantiates the GPU particle engine, optionally follows entity transform, and exposes transport controls on the handle (play, stop, burst, …).

Minimal example​

website/snippets/behaviors/catalog/particle-emitter.ts:

import { ParticleEmitterBehavior, particlePresets } from '@zylem/game-lib/behavior';

const emitter = torch.use(ParticleEmitterBehavior, {
effect: particlePresets.fire.blaze(),
autoplay: true,
followPosition: true,
followRotation: false,
});

Options​

FieldDefaultNotes
effectrequiredPreset or custom definition.
autoplaytrueStart on spawn.
followPosition / followRotationtrue / trueParent emitter to entity.
autoDestroyfalseRemove entity when a one-shot effect finishes.
localOffset—Spawn offset in entity space.

Presets​

particlePresets groups bursts (burst, smoke) and themed families (fire, water, gas, electricity, magic) with tunable count, life, size, and speed.

Handle​

  • play(), stop(), pause(), restart(), burst(), isPlaying(), getSystem().

Pitfalls​

  • Particle construction needs a 2D canvas context in the environment; headless tests stub canvas (see game-lib particle emitter tests).
  • Looping effects stay “playing” until stopped; use short one-shot presets for tests.
  • worldSpace on preset options is retained for API compatibility; follow flags on the behavior control parenting.

API reference​