Skip to content

Emitter<DataType, ParticleType>

Class responsible for spawning and managing particles using various behaviors.

Emitter is the core class of the particle system, handling particle creation, updating, and recycling. It utilizes a set of behaviors to define how particles are initialized and updated over their lifetime.

Example

ts
const emitter = new Emitter(particleContainer, {
    emitterVersion: 0,
    minParticleLifetime: 1,
    maxParticleLifetime: 3,
    spawnInterval: 0.1,
    maxParticles: 500,
    alphaBehavior: {
        mode: "list",
        list: [1, 0],
    },
    scaleBehavior: {
        mode: "random",
        xList: [0.5, 1],
        yList: [0.5, 1],
    },
});

emitter.play();

Type Parameters

DataType

DataType extends BaseParticleData = BaseParticleData

Type describing the data object stored on particles.

ParticleType

ParticleType extends IEmitterParticle<DataType> = EmitterParticle<DataType>

Type describing the particle used within the emitter.

Constructors

Constructor

ts
new Emitter<DataType, ParticleType>(
   parent,
   initialConfig?,
options?): Emitter<DataType, ParticleType>;

Creates a new Emitter.

Parameters

parent

ParticleContainer

Parent ParticleContainer to which particles will be added.

initialConfig?

EmitterConfig

Optional initial configuration for the emitter.

options?

EmitterOptions<DataType, ParticleType>

Optional factories and initializers for custom particle data and particles.

Returns

Emitter<DataType, ParticleType>

Accessors

addAtBack

Get Signature

ts
get addAtBack(): boolean;

Whether to add new particles at the back of the container.

Returns

boolean

Set Signature

ts
set addAtBack(value): void;
Parameters
value

boolean

Returns

void


alphaBehavior

Get Signature

ts
get alphaBehavior(): AlphaBehavior<DataType, ParticleType>;

Alpha behavior of the emitter.

Returns

AlphaBehavior<DataType, ParticleType>


colorBehavior

Get Signature

ts
get colorBehavior(): ColorBehavior<DataType, ParticleType>;

Color behavior of the emitter.

Returns

ColorBehavior<DataType, ParticleType>


ease

Get Signature

ts
get ease():
  | "linear"
  | "power2.in"
  | "power3.in"
  | "power4.in"
  | "power5.in"
  | "power2.out"
  | "power3.out"
  | "power4.out"
  | "power5.out"
  | "power2.inout"
  | "power3.inout"
  | "power4.inout"
  | "power5.inout"
  | "back.in"
  | "back.out"
  | "back.inout"
  | "bounce.in"
  | "bounce.out"
  | "bounce.inout"
  | "circle.in"
  | "circle.out"
  | "circle.inout"
  | "elastic.in"
  | "elastic.out"
  | "elastic.inout"
  | "sine.in"
  | "sine.out"
  | "sine.inout";

Ease applied to particle lifetime.

Returns

| "linear" | "power2.in" | "power3.in" | "power4.in" | "power5.in" | "power2.out" | "power3.out" | "power4.out" | "power5.out" | "power2.inout" | "power3.inout" | "power4.inout" | "power5.inout" | "back.in" | "back.out" | "back.inout" | "bounce.in" | "bounce.out" | "bounce.inout" | "circle.in" | "circle.out" | "circle.inout" | "elastic.in" | "elastic.out" | "elastic.inout" | "sine.in" | "sine.out" | "sine.inout"

Set Signature

ts
set ease(value): void;
Parameters
value

"linear" | "power2.in" | "power3.in" | "power4.in" | "power5.in" | "power2.out" | "power3.out" | "power4.out" | "power5.out" | "power2.inout" | "power3.inout" | "power4.inout" | "power5.inout" | "back.in" | "back.out" | "back.inout" | "bounce.in" | "bounce.out" | "bounce.inout" | "circle.in" | "circle.out" | "circle.inout" | "elastic.in" | "elastic.out" | "elastic.inout" | "sine.in" | "sine.out" | "sine.inout"

Returns

void


isEmitting

Get Signature

ts
get isEmitting(): boolean;

Whether the emitter is currently emitting new particles.

Returns

boolean


isPaused

Get Signature

ts
get isPaused(): boolean;

Whether the emitter is currently paused.

Returns

boolean


maxLifetime

Get Signature

ts
get maxLifetime(): number;

Maximum lifetime of particles in seconds.

Returns

number

Set Signature

ts
set maxLifetime(value): void;
Parameters
value

number

Returns

void


maxParticles

Get Signature

ts
get maxParticles(): number;

Maximum number of particles allowed in the emitter.

Returns

number

Set Signature

ts
set maxParticles(value): void;
Parameters
value

number

Returns

void


minLifetime

Get Signature

ts
get minLifetime(): number;

Minimum lifetime of particles in seconds.

Returns

number

Set Signature

ts
set minLifetime(value): void;
Parameters
value

number

Returns

void


movementBehavior

Get Signature

ts
get movementBehavior(): MovementBehavior<DataType, ParticleType>;

Movement behavior of the emitter.

Returns

MovementBehavior<DataType, ParticleType>


parent

Get Signature

ts
get parent(): ParticleContainer;

Parent ParticleContainer of the emitter.

Returns

ParticleContainer


particleCount

Get Signature

ts
get particleCount(): number;

Number of active particles in the emitter.

Returns

number


particlesPerWave

Get Signature

ts
get particlesPerWave(): number;

Number of particles to spawn per wave.

Returns

number

Set Signature

ts
set particlesPerWave(value): void;
Parameters
value

number

Returns

void


rotationBehavior

Get Signature

ts
get rotationBehavior(): RotationBehavior<DataType, ParticleType>;

Rotation behavior of the emitter.

Returns

RotationBehavior<DataType, ParticleType>


scaleBehavior

Get Signature

ts
get scaleBehavior(): ScaleBehavior<DataType, ParticleType>;

Scale behavior of the emitter.

Returns

ScaleBehavior<DataType, ParticleType>


spawnBehavior

Get Signature

ts
get spawnBehavior(): SpawnBehavior<DataType, ParticleType>;

Spawn behavior of the emitter.

Returns

SpawnBehavior<DataType, ParticleType>


spawnChance

Get Signature

ts
get spawnChance(): number;

Chance of spawning a particle (0.0 - 1.0).

Returns

number

Set Signature

ts
set spawnChance(value): void;
Parameters
value

number

Returns

void


spawnInterval

Get Signature

ts
get spawnInterval(): number;

Interval between particle spawns in seconds.

Returns

number

Set Signature

ts
set spawnInterval(value): void;
Parameters
value

number

Returns

void


textureBehavior

Get Signature

ts
get textureBehavior(): TextureBehavior<DataType, ParticleType>;

Texture behavior of the emitter.

Returns

TextureBehavior<DataType, ParticleType>


version

Get Signature

ts
get version(): string;

Current version of the emitter.

Returns

string

Methods

addToActiveInitBehaviors()

ts
addToActiveInitBehaviors(behavior): void;

Adds a behavior to the active init behaviors.

Parameters

behavior

InitBehavior<DataType, ParticleType>

Behavior to add.

Returns

void


addToActiveUpdateBehaviors()

ts
addToActiveUpdateBehaviors(behavior): void;

Adds a behavior to the active update behaviors.

Parameters

behavior

UpdateBehavior<DataType, ParticleType>

Behavior to add.

Returns

void


applyConfig()

ts
applyConfig(config): void;

Applies a configuration to the emitter.

Parameters

config

EmitterConfig

Configuration to apply.

Returns

void


getConfig()

ts
getConfig(): EmitterConfig;

Retrieves the current configuration for emitter and its behaviors.

Returns

EmitterConfig

Current configuration object.


isBehaviorInitActive()

ts
isBehaviorInitActive(behavior): boolean;

Checks if a behavior is currently active in the emitter's init behaviors.

Parameters

behavior

InitBehavior<DataType, ParticleType>

Behavior to check.

Returns

boolean

Whether the behavior is active.


isBehaviorUpdateActive()

ts
isBehaviorUpdateActive(behavior): boolean;

Checks if a behavior is currently active in the emitter's update behaviors.

Parameters

behavior

UpdateBehavior<DataType, ParticleType>

Behavior to check.

Returns

boolean

Whether the behavior is active.


pause()

ts
pause(): void;

Pauses the emitter by unhooking from the shared ticker.

Returns

void


play()

ts
play(): void;

Starts the emitter and hooks into the shared ticker.

Returns

void


prewarm()

ts
prewarm(time): void;

Prewarms the emitter by simulating particle spawning and updating for a given time.

Parameters

time

number

Time in seconds to prewarm the emitter.

Returns

void


removeFromActiveInitBehaviors()

ts
removeFromActiveInitBehaviors(behavior): void;

Removes a behavior from the active init behaviors.

Parameters

behavior

InitBehavior<DataType, ParticleType>

Behavior to remove.

Returns

void


removeFromActiveUpdateBehaviors()

ts
removeFromActiveUpdateBehaviors(behavior): void;

Removes a behavior from the active update behaviors.

Parameters

behavior

UpdateBehavior<DataType, ParticleType>

Behavior to remove.

Returns

void


resume()

ts
resume(): void;

Resumes the emitter by rehooking into the shared ticker.

Returns

void


stop()

ts
stop(instant): void;

Stops new particles from spawning, and lets existing particles die naturally.

Parameters

instant

boolean = false

When true, particles are removed instantly.

Returns

void