Particles. ParticleEmitter

Particle Emitter - Spawns particles with the given settings

Constructor

new ParticleEmitter(pos, angleopt, emitSizeopt, emitTimeopt, emitRateopt, emitConeAngleopt, tileInfoopt, colorStartAopt, colorStartBopt, colorEndAopt, colorEndBopt, particleTimeopt, sizeStartopt, sizeEndopt, speedopt, angleSpeedopt, dampingopt, angleDampingopt, gravityScaleopt, particleConeAngleopt, fadeRateopt, randomnessopt, collideTilesopt, additiveopt, randomColorLinearopt, renderOrderopt, localSpaceopt)

Create a particle system with the given settings

Parameters:
NameTypeAttributesDefaultDescription
posVector2

World space position of the emitter

anglenumber<optional>

Angle to emit the particles

emitSizenumber | Vector2<optional>
0

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

emitTimenumber<optional>
0

How long to stay alive (0 is forever)

emitRatenumber<optional>
100

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

emitConeAnglenumber<optional>
PI

Local angle to apply velocity to particles from emitter

tileInfoTileInfo<optional>

Tile info to render particles (undefined is untextured)

colorStartAColor<optional>
WHITE

Color at start of life 1, randomized between start colors

colorStartBColor<optional>
WHITE

Color at start of life 2, randomized between start colors

colorEndAColor<optional>
CLEAR_WHITE

Color at end of life 1, randomized between end colors

colorEndBColor<optional>
CLEAR_WHITE

Color at end of life 2, randomized between end colors

particleTimenumber<optional>
0.5

How long particles live

sizeStartnumber<optional>
0.1

How big are particles at start

sizeEndnumber<optional>
1

How big are particles at end

speednumber<optional>
0.1

How fast are particles when spawned

angleSpeednumber<optional>
0.05

How fast are particles rotating

dampingnumber<optional>
1

How much to dampen particle speed

angleDampingnumber<optional>
1

How much to dampen particle angular speed

gravityScalenumber<optional>
0

How much gravity effect particles

particleConeAnglenumber<optional>

Cone for start particle angle

fadeRatenumber<optional>
0.1

How quick to fade particles at start/end in percent of life

randomnessnumber<optional>
0.2

Apply extra randomness percent

collideTilesboolean<optional>
false

Do particles collide against tiles

additiveboolean<optional>
false

Should particles use additive blend

randomColorLinearboolean<optional>
true

Should color be randomized linearly or across each component

renderOrdernumber<optional>

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

localSpaceboolean<optional>
false

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

Example
// create a particle emitter
let pos = vec2(2,3);
let particleEmitter = new ParticleEmitter
(
    pos, 0, 1, 0, 500, PI,      // pos, angle, emitSize, emitTime, emitRate, emitCone
    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, particleSpeed, particleAngleSpeed
    .99, 1, 1, PI, .05,  // damping, angleDamping, gravityScale, particleCone, fadeRate,
    .5, 1                // randomness, collide, additive, randomColorLinear, renderOrder
);

Extends

  • EngineObject

Members

additive

Properties
TypeDescription
boolean

Should particles use additive blend

angleDamping

Properties
TypeDescription
number

How much to dampen particle angular speed

angleSpeed

Properties
TypeDescription
number

How fast are particles rotating

collideTiles

Properties
TypeDescription
boolean

Do particles collide against tiles

colorEndA

Properties
TypeDescription
Color

Color at end of life 1, randomized between end colors

colorEndB

Properties
TypeDescription
Color

Color at end of life 2, randomized between end colors

colorStartA

Properties
TypeDescription
Color

Color at start of life 1, randomized between start colors

colorStartB

Properties
TypeDescription
Color

Color at start of life 2, randomized between start colors

damping

Properties
TypeDescription
number

How much to dampen particle speed

emitCircle

Properties
TypeDescription
boolean

Should particles be emitted in a circle

emitConeAngle

Properties
TypeDescription
number

Local angle to apply velocity to particles from emitter

emitRate

Properties
TypeDescription
number

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

emitSize

Properties
TypeDescription
number | Vector2

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

emitTime

Properties
TypeDescription
number

How long to stay alive (0 is forever)

emitTimeBuffer

Properties
TypeDescription
number

Track particle emit time

fadeRate

Properties
TypeDescription
number

How quick to fade in particles at start/end in percent of life

gravityScale

Properties
TypeDescription
number

How much gravity affects particles

localSpace

Properties
TypeDescription
boolean

Should it be in local space of emitter

particleCollideCallback

Properties
TypeDescription
ParticleCollideCallback

Callback when particle collides

particleConeAngle

Properties
TypeDescription
number

Cone for start particle angle

particleCreateCallback

Properties
TypeDescription
ParticleCallback

Callback when particle is created

particleDestroyCallback

Properties
TypeDescription
ParticleCallback

Callback when particle is destroyed

particleTime

Properties
TypeDescription
number

How long particles live

particles

Properties
TypeDescription
Array.<Particle>

Array of particles for this emitter

randomColorLinear

Properties
TypeDescription
boolean

Should color be randomized linearly or across each component

randomness

Properties
TypeDescription
number

Apply extra randomness percent

sizeEnd

Properties
TypeDescription
number

How big are particles at end

sizeStart

Properties
TypeDescription
number

How big are particles at start

speed

Properties
TypeDescription
number

How fast are particles when spawned

trailScale

Properties
TypeDescription
number

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

velocityInheritance

Properties
TypeDescription
number

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

Methods

destroy(immediateopt)

Destroy the particle emitter

Parameters:
NameTypeAttributesDefaultDescription
immediateboolean<optional>
false

should particle emitters and other attached effects be allowed to die off

emitParticle() → {Particle}

Spawn one particle

Returns:
Type: 
Particle

isActive()

is emitter actively spawning

render()

Render all particles for this emitter

update()

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

updatePhysics()

Particle emitters do not have physics