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
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
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?
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
get addAtBack(): boolean;Whether to add new particles at the back of the container.
Returns
boolean
Set Signature
set addAtBack(value): void;Parameters
value
boolean
Returns
void
alphaBehavior
Get Signature
get alphaBehavior(): AlphaBehavior<DataType, ParticleType>;Alpha behavior of the emitter.
Returns
AlphaBehavior<DataType, ParticleType>
colorBehavior
Get Signature
get colorBehavior(): ColorBehavior<DataType, ParticleType>;Color behavior of the emitter.
Returns
ColorBehavior<DataType, ParticleType>
ease
Get Signature
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
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
get isEmitting(): boolean;Whether the emitter is currently emitting new particles.
Returns
boolean
isPaused
Get Signature
get isPaused(): boolean;Whether the emitter is currently paused.
Returns
boolean
maxLifetime
Get Signature
get maxLifetime(): number;Maximum lifetime of particles in seconds.
Returns
number
Set Signature
set maxLifetime(value): void;Parameters
value
number
Returns
void
maxParticles
Get Signature
get maxParticles(): number;Maximum number of particles allowed in the emitter.
Returns
number
Set Signature
set maxParticles(value): void;Parameters
value
number
Returns
void
minLifetime
Get Signature
get minLifetime(): number;Minimum lifetime of particles in seconds.
Returns
number
Set Signature
set minLifetime(value): void;Parameters
value
number
Returns
void
movementBehavior
Get Signature
get movementBehavior(): MovementBehavior<DataType, ParticleType>;Movement behavior of the emitter.
Returns
MovementBehavior<DataType, ParticleType>
parent
Get Signature
get parent(): ParticleContainer;Parent ParticleContainer of the emitter.
Returns
ParticleContainer
particleCount
Get Signature
get particleCount(): number;Number of active particles in the emitter.
Returns
number
particlesPerWave
Get Signature
get particlesPerWave(): number;Number of particles to spawn per wave.
Returns
number
Set Signature
set particlesPerWave(value): void;Parameters
value
number
Returns
void
rotationBehavior
Get Signature
get rotationBehavior(): RotationBehavior<DataType, ParticleType>;Rotation behavior of the emitter.
Returns
RotationBehavior<DataType, ParticleType>
scaleBehavior
Get Signature
get scaleBehavior(): ScaleBehavior<DataType, ParticleType>;Scale behavior of the emitter.
Returns
ScaleBehavior<DataType, ParticleType>
spawnBehavior
Get Signature
get spawnBehavior(): SpawnBehavior<DataType, ParticleType>;Spawn behavior of the emitter.
Returns
SpawnBehavior<DataType, ParticleType>
spawnChance
Get Signature
get spawnChance(): number;Chance of spawning a particle (0.0 - 1.0).
Returns
number
Set Signature
set spawnChance(value): void;Parameters
value
number
Returns
void
spawnInterval
Get Signature
get spawnInterval(): number;Interval between particle spawns in seconds.
Returns
number
Set Signature
set spawnInterval(value): void;Parameters
value
number
Returns
void
textureBehavior
Get Signature
get textureBehavior(): TextureBehavior<DataType, ParticleType>;Texture behavior of the emitter.
Returns
TextureBehavior<DataType, ParticleType>
version
Get Signature
get version(): string;Current version of the emitter.
Returns
string
Methods
addToActiveInitBehaviors()
addToActiveInitBehaviors(behavior): void;Adds a behavior to the active init behaviors.
Parameters
behavior
InitBehavior<DataType, ParticleType>
Behavior to add.
Returns
void
addToActiveUpdateBehaviors()
addToActiveUpdateBehaviors(behavior): void;Adds a behavior to the active update behaviors.
Parameters
behavior
UpdateBehavior<DataType, ParticleType>
Behavior to add.
Returns
void
applyConfig()
applyConfig(config): void;Applies a configuration to the emitter.
Parameters
config
Configuration to apply.
Returns
void
getConfig()
getConfig(): EmitterConfig;Retrieves the current configuration for emitter and its behaviors.
Returns
Current configuration object.
isBehaviorInitActive()
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()
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()
pause(): void;Pauses the emitter by unhooking from the shared ticker.
Returns
void
play()
play(): void;Starts the emitter and hooks into the shared ticker.
Returns
void
prewarm()
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()
removeFromActiveInitBehaviors(behavior): void;Removes a behavior from the active init behaviors.
Parameters
behavior
InitBehavior<DataType, ParticleType>
Behavior to remove.
Returns
void
removeFromActiveUpdateBehaviors()
removeFromActiveUpdateBehaviors(behavior): void;Removes a behavior from the active update behaviors.
Parameters
behavior
UpdateBehavior<DataType, ParticleType>
Behavior to remove.
Returns
void
resume()
resume(): void;Resumes the emitter by rehooking into the shared ticker.
Returns
void
stop()
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