Options
All
  • Public
  • Public/Protected
  • All
Menu

A particle emitter.

Hierarchy

  • Emitter

Index

Constructors

  • Parameters

    • particleParent: Container

      The container to add the particles to.

    • config: EmitterConfigV3

      A configuration object containing settings for the emitter.

    Returns Emitter

Properties

_activeParticlesFirst: Particle

The particles that are active and on the display list. This is the first particle in a linked list.

_activeParticlesLast: Particle

The particles that are active and on the display list. This is the last particle in a linked list.

_autoUpdate: boolean

If the update function is called automatically from the shared ticker. Setting this to false requires calling the update function manually.

_completeCallback: () => void

Type declaration

    • (): void
    • A callback for when all particles have died out. This is set by playOnceAndDestroy() or playOnce();

      Returns void

_destroyWhenComplete: boolean

If the emitter should destroy itself when all particles have died out. This is set by playOnceAndDestroy();

_emit: boolean

If particles should be emitted during update() calls. Setting this to false stops new particles from being created, but allows existing ones to die out.

_emitterLife: number

The life of the emitter in seconds.

_frequency: number

Time between particle spawns in seconds.

_origConfig: any

The original config object that this emitter was initialized with.

_parent: Container

The container to add particles to.

_poolFirst: Particle

The particles that are not currently being used. This is the first particle in a linked list.

_posChanged: boolean

If either ownerPos or spawnPos has changed since the previous update.

_prevEmitterPos: Point

The origin + spawnPos in the previous update, so that the spawn position can be interpolated to space out particles better.

_prevPosIsValid: boolean

If _prevEmitterPos is valid, to prevent interpolation on the first update

_spawnTimer: number

The timer for when to spawn particles in seconds, where numbers less than 0 mean that particles should be spawned.

addAtBack: boolean

If particles should be added at the back of the display list instead of the front.

customEase: SimpleEase

An easing function for nonlinear interpolation of values. Accepts a single parameter of time as a value from 0-1, inclusive. Expected outputs are values from 0-1, inclusive.

emitterLifetime: number

The amount of time in seconds to emit for before setting emit to false. A value of -1 is an unlimited amount of time.

initBehaviors: (IEmitterBehavior | typeof PositionParticle)[]

Active initialization behaviors for this emitter.

maxLifetime: number

The maximum lifetime for a particle, in seconds.

maxParticles: number

Maximum number of particles to keep alive at a time. If this limit is reached, no more particles will spawn until some have died.

minLifetime: number

The minimum lifetime for a particle, in seconds.

ownerPos: Point

The world position of the emitter's owner, to add spawnPos to when spawning particles. To change this, use updateOwnerPos().

particleCount: number

The current number of active particles.

particlesPerWave: number

Number of particles to spawn time that the frequency allows for particles to spawn.

recycleBehaviors: IEmitterBehavior[]

Active recycle behaviors for this emitter.

rotation: number

Rotation of the emitter or emitter's owner in degrees. This is added to the calculated spawn angle. To change this, use rotate().

spawnChance: number

Chance that a particle will be spawned on each opportunity to spawn one. 0 is 0%, 1 is 100%.

spawnPos: Point

Position at which to spawn particles, relative to the emitter's owner's origin. For example, the flames of a rocket travelling right might have a spawnPos of {x:-50, y:0}. to spawn at the rear of the rocket. To change this, use updateSpawnPos().

updateBehaviors: IEmitterBehavior[]

Active update behaviors for this emitter.

knownBehaviors: {} = {}

Type declaration

Accessors

  • get autoUpdate(): boolean
  • set autoUpdate(value: boolean): void
  • If the update function is called automatically from the shared ticker. Setting this to false requires calling the update function manually.

    Returns boolean

  • If the update function is called automatically from the shared ticker. Setting this to false requires calling the update function manually.

    Parameters

    • value: boolean

    Returns void

  • get destroyed(): boolean
  • If this emitter has been destroyed. Note that a destroyed emitter can still be reused, after having a new parent set and being reinitialized.

    Returns boolean

  • get emit(): boolean
  • set emit(value: boolean): void
  • If particles should be emitted during update() calls. Setting this to false stops new particles from being created, but allows existing ones to die out.

    Returns boolean

  • If particles should be emitted during update() calls. Setting this to false stops new particles from being created, but allows existing ones to die out.

    Parameters

    • value: boolean

    Returns void

  • get frequency(): number
  • set frequency(value: number): void
  • Time between particle spawns in seconds. If this value is not a number greater than 0, it will be set to 1 (particle per second) to prevent infinite loops.

    Returns number

  • Time between particle spawns in seconds. If this value is not a number greater than 0, it will be set to 1 (particle per second) to prevent infinite loops.

    Parameters

    • value: number

    Returns void

  • get parent(): Container
  • set parent(value: Container): void
  • The container to add particles to. Settings this will dump any active particles.

    Returns Container

  • The container to add particles to. Settings this will dump any active particles.

    Parameters

    • value: Container

    Returns void

Methods

  • cleanup(): void
  • destroy(): void
  • emitNow(): void
  • Emits a single wave of particles, using standard spawnChance & particlesPerWave settings. Does not affect regular spawning through the frequency, and ignores the emit property. The max particle count is respected, however, so if there are already too many particles then nothing will happen.

    Returns void

  • fillPool(count: number): void
  • Fills the pool with the specified number of particles, so that they don't have to be instantiated later.

    Parameters

    • count: number

      The number of particles to create.

    Returns void

  • Gets the instantiated behavior of the specified type, if it is present on this emitter.

    Parameters

    • type: string

      The behavior type to find.

    Returns IEmitterBehavior

  • Sets up the emitter based on the config settings.

    Parameters

    • config: EmitterConfigV3

      A configuration object containing settings for the emitter.

    Returns void

  • playOnce(callback?: () => void): void
  • Starts emitting particles and optionally calls a callback when particle emission is complete.

    Parameters

    • Optional callback: () => void

      Callback for when emission is complete (all particles have died off)

        • (): void
        • Returns void

    Returns void

  • playOnceAndDestroy(callback?: () => void): void
  • Starts emitting particles, sets autoUpdate to true, and sets up the Emitter to destroy itself when particle emission is complete.

    Parameters

    • Optional callback: () => void

      Callback for when emission is complete (all particles have died off)

        • (): void
        • Returns void

    Returns void

  • recycle(particle: Particle, fromCleanup?: boolean): void
  • Recycles an individual particle. For internal use only.

    internal

    Parameters

    • particle: Particle

      The particle to recycle.

    • fromCleanup: boolean = false

      If this is being called to manually clean up all particles.

    Returns void

  • resetPositionTracking(): void
  • Prevents emitter position interpolation in the next update. This should be used if you made a major position change of your emitter's owner that was not normal movement.

    Returns void

  • rotate(newRot: number): void
  • Sets the rotation of the emitter to a new value. This rotates the spawn position in addition to particle direction.

    Parameters

    • newRot: number

      The new rotation, in degrees.

    Returns void

  • update(delta: number): void
  • Updates all particles spawned by this emitter and emits new ones.

    Parameters

    • delta: number

      Time elapsed since the previous frame, in seconds.

    Returns void

  • updateOwnerPos(x: number, y: number): void
  • Changes the position of the emitter's owner. You should call this if you are adding particles to the world container that your emitter's owner is moving around in.

    Parameters

    • x: number

      The new x value of the emitter's owner.

    • y: number

      The new y value of the emitter's owner.

    Returns void

  • updateSpawnPos(x: number, y: number): void
  • Changes the spawn position of the emitter.

    Parameters

    • x: number

      The new x value of the spawn position for the emitter.

    • y: number

      The new y value of the spawn position for the emitter.

    Returns void

  • Registers a new behavior, so that it will be recognized when initializing emitters. Behaviors registered later with duplicate types will override older ones, although there is no limit on the allowed types.

    Parameters

    Returns void

Generated using TypeDoc