nape-js API
    Preparing search index...

    Class ParticleEmitter

    Physics-aware particle emitter — a pooled, lifecycle-managed swarm of dynamic bodies. Each particle is a real Body with a Circle or Polygon shape, so it collides with the world, reacts to gravity / fluids / forces, and triggers callbacks like any other body.

    // Volcano: emit lava drops upward in a 40-deg cone.
    const volcano = new ParticleEmitter({
    space,
    origin: new Vec2(400, 100),
    velocity: {
    kind: "cone",
    direction: -Math.PI / 2,
    spread: Math.PI / 9,
    speedMin: 350,
    speedMax: 600,
    },
    rate: 80,
    lifetimeMin: 4,
    lifetimeMax: 8,
    particleRadius: 3,
    maxParticles: 600,
    });

    // Each frame, before space.step():
    volcano.update(1 / 60);
    space.step(1 / 60);
    Index

    Constructors

    Properties

    allowRotation: boolean
    bounds: ParticleBounds | null
    burstCount: number
    burstInterval: number
    enabled: boolean
    lifetimeMax: number
    lifetimeMin: number
    maxParticles: number
    onCollide: ((body: Body, other: Body) => void) | null
    onDeath: ((body: Body, reason: ParticleDeathReason) => void) | null
    onSpawn: ((state: ParticleSpawnState, body: Body) => void) | null
    onUpdate: ((body: Body, age: number, dt: number) => void) | null
    origin: Vec2 | Body
    overflowPolicy: ParticleOverflowPolicy
    particleCbType: CbType | null
    particleFilter: InteractionFilter
    particleMaterial: Material
    particlePolygon: Vec2[] | null
    particleRadius: number
    particleShape: ParticleShape
    random: () => number
    rate: number
    space: Space
    velocity: VelocityPattern

    Accessors

    Methods

    • Advance lifetimes, fire onUpdate, kill expired / out-of-bounds particles, and run continuous / periodic spawning.

      Call once per frame, before space.step(). dt should match the step size you'll pass to space.step().

      Parameters

      • dt: number

      Returns void