LittleJS 1.28.0

Particles

ParticleEmitter

Particle Emitter - Spawns particles with the given settings

Extends EngineObject

Constructor

new ParticleEmitter(pos, angle, emitSize, emitTime, emitRate, emitConeAngle, tileInfo, colorStartA, colorStartB, colorEndA, colorEndB, particleTime, sizeStart, sizeEnd, speed, angleSpeed, damping, angleDamping, gravityScale, particleConeAngle, fadeRate, randomness, collideLevel, additive, randomColorLinear, renderOrder, localSpace)engineParticles.js:49

Create a particle system with the given settings

pos Vector2

World space position of the emitter

angle number optional

Angle to emit the particles

emitSize number|Vector2 optional, default 0

World space size of the emitter (float for circle diameter, vec2 for rect)

emitTime number optional, default 0

How long to stay alive (0 is forever)

emitRate number optional, default 100

How many particles per second to spawn, does not emit if 0

emitConeAngle number optional, default PI

Half angle of the cone around the emitter's angle that particles move along, PI is every direction

tileInfo TileInfo optional

Tile info to render particles (undefined is untextured)

colorStartA Color optional, default WHITE

Color at start of life 1, randomized between start colors

colorStartB Color optional, default WHITE

Color at start of life 2, randomized between start colors

colorEndA Color optional, default CLEAR_WHITE

Color at end of life 1, randomized between end colors

colorEndB Color optional, default CLEAR_WHITE

Color at end of life 2, randomized between end colors

particleTime number optional, default 0.5

How long particles live

sizeStart number optional, default 0.1

How big are particles at start

sizeEnd number optional, default 1

How big are particles at end

speed number optional, default 0.1

How fast are particles when spawned, in world units per frame (at 60fps, so multiply units/sec by 1/60)

angleSpeed number optional, default 0.05

How fast are particles rotating, in radians per frame (at 60fps)

damping number optional, default 1

How much to dampen particle speed, per-frame velocity multiplier (1 = no damping, .9 = lose 10% speed each frame)

angleDamping number optional, default 1

How much to dampen particle angular speed, per-frame multiplier (1 = no damping)

gravityScale number optional, default 0

How much gravity affects particles

particleConeAngle number optional

Half angle each side of the emitter's angle for a particle's start angle, PI is any angle

fadeRate number optional, default 0.1

Fraction of life spent fading: half at fade-in (start), half at fade-out (end). e.g. .2 = 10% fade-in, 80% full opacity, 10% fade-out

randomness number optional, default 0.2

Apply extra randomness percent

collideLevel boolean optional, default false

Do particles collide with the level's tiles, world space emitters only

additive boolean optional, default false

Should particles use additive blend

randomColorLinear boolean optional, default true

Should color be randomized linearly or across each component

renderOrder number optional

Render order for particles (additive is above other stuff by default)

localSpace boolean optional, default false

Should it be in local space of emitter (world space is default)

// create a particle emitter
let pos = vec2(2,3);
let particleEmitter = new ParticleEmitter
(
    pos, 0, 1, 0, 500, PI,      // pos, angle, emitSize, emitTime, emitRate, emitConeAngle
    tile(0, 16),                // tileInfo
    rgb(1,1,1,1), rgb(0,0,0,1), // colorStartA, colorStartB
    rgb(1,1,1,0), rgb(0,0,0,0), // colorEndA, colorEndB
    1, .2, .2, .1, .05,  // particleTime, sizeStart, sizeEnd, speed, angleSpeed
    .99, 1, 1, PI, .05,  // damping, angleDamping, gravityScale, particleConeAngle, fadeRate
    .5, true             // randomness, collideLevel
);

Members

Methods

Inherited from EngineObject

Members

additive : booleanengineParticles.js:184

Should particles use additive blend

angleDamping : numberengineParticles.js:172

Per-frame angular velocity multiplier (1 = no damping)

angleSpeed : numberengineParticles.js:168

Particle angular speed when spawned, in radians per frame (at 60fps)

collideLevel : booleanengineParticles.js:182

Do particles collide with the level's tiles

Color at end of life 1, randomized between end colors

Color at end of life 2, randomized between end colors

Color at start of life 1, randomized between start colors

Color at start of life 2, randomized between start colors

damping : numberengineParticles.js:170

Per-frame velocity multiplier (1 = no damping, .9 = lose 10% speed each frame)

emitCircle : booleanengineParticles.js:135

Should particles be emitted in a circle

emitConeAngle : numberengineParticles.js:144

Half angle of the cone around the emitter's angle that particles move along, PI is every direction

emitElapsed : numberengineParticles.js:219

Seconds of its emit time it has emitted for, counted by its updates

emitRate : numberengineParticles.js:142

How many particles per second to spawn, does not emit if 0

World space size of the emitter, x is the diameter when emitCircle is set

emitTime : numberengineParticles.js:140

How long to emit for in seconds, 0 is forever; raised while its particles are still alive, it emits again for the added time

emitTimeBuffer : numberengineParticles.js:216

Particles owed to the emit rate, starts at one so the first comes out at once

fadeRate : numberengineParticles.js:178

Fraction of life spent fading, split half at start and half at end (e.g. .2 = 10% fade-in + 10% fade-out)

finishCallback : (function(ParticleEmitter): void)|undefinedengineParticles.js:212
gravity : numberengineParticles.js:195

The effect's own fall, added to each particle's velocity y every frame, on top of the world's gravity times gravityScale; an effect that sets its own looks the same in any game

gravityScale : numberengineParticles.js:174

How much gravity affects particles

localSpace : booleanengineParticles.js:186

Should it be in local space of emitter

particleCollideCallback : ParticleCollideCallback|undefinedengineParticles.js:204

Callback when particle collides

particleConeAngle : numberengineParticles.js:176

Half angle each side of the emitter's angle for a particle's start angle, PI is any angle

particleCreateCallback : ParticleCallback|undefinedengineParticles.js:198

Callback when particle is created

particleDestroyCallback : ParticleCallback|undefinedengineParticles.js:201

Callback when particle is destroyed

Array of particles for this emitter

particleTime : numberengineParticles.js:160

How long particles live

particleUpdateCallback : ParticleCallback|undefinedengineParticles.js:207

Callback each time a particle updates, after it moves

previousPos : Vector2|undefinedengineParticles.js:226
randomColorLinear : booleanengineParticles.js:156

Should color be randomized linearly or across each component

randomness : numberengineParticles.js:180

Apply extra randomness percent

Grows the whole effect as each particle is born: the spawn area, the particles' sizes, speed and fall, so it looks the same only bigger; 1 is as made, and a particle keeps the scale it was born with, so a change never moves the ones already out

sizeEnd : numberengineParticles.js:164

How big are particles at end

sizeStart : numberengineParticles.js:162

How big are particles at start

Particle speed when spawned, in world units per frame (at 60fps)

trailScale : numberengineParticles.js:188

If non zero the particle is drawn as a trail, stretched in the direction of velocity

velocityInheritance : numberengineParticles.js:214

Percentage of velocity to pass to particles (0-1)

Methods

destroy(immediate)engineParticles.js:400

Destroy the particle emitter

immediate boolean optional, default false

true removes it and its particles at once, with no particleDestroyCallback for them, false stops emitting and lets the particles finish first

Spawn one particle

isActive() → booleanengineParticles.js:395

is emitter actively spawning

Render all particles for this emitter

Update the emitter to spawn particles, called automatically by engine once each frame

updatePhysics()engineParticles.js:377

Particle emitters do not have physics