ParticleEmitter

Particle Emitter - Spawns particles with the given settings

Constructor

new ParticleEmitter(position, 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
positionVector2

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>
(1,1,1,1)

Color at start of life 1, randomized between start colors

colorStartBColor<optional>
(1,1,1,1)

Color at start of life 2, randomized between start colors

colorEndAColor<optional>
(1,1,1,0)

Color at end of life 1, randomized between end colors

colorEndBColor<optional>
(1,1,1,0)

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 addtive 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, emiteCone
    tile(0, 16),                // tileInfo
    rgb(1,1,1),   rgb(0,0,0),   // colorStartA, colorStartB
    rgb(1,1,1,0), rgb(0,0,0,0), // colorEndA, colorEndB
    2, .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

Members

additive

Properties
TypeDescription
Boolean

Should particles use addtive blend

additiveColor

Properties
TypeDescription
Color

Additive color to apply when rendered

angle

Properties
TypeDescription
Number

Angle to rotate the object

angleDamping

Properties
TypeDescription
Number

How much to dampen particle angular speed

angleSpeed

Properties
TypeDescription
Number

How fast are particles rotating

angleVelocity

Properties
TypeDescription
Number

Angular velocity of the object

children

Properties
TypeDescription
Array

List of children of this object

clampSpeedLinear

Properties
TypeDescription
Boolean

Limit object speed using linear or circular math

collideRaycast

Properties
TypeDescription
Boolean

Object collides with raycasts

collideSolidObjects

Properties
TypeDescription
Boolean

Object collides with solid objects

collideTiles

Properties
TypeDescription
Boolean

Do particles collide against tiles

color

Properties
TypeDescription
Color

Color to apply when rendered

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

drawSize

Properties
TypeDescription
Vector2

Size of object used for drawing, uses size if not set

elasticity

Properties
NameTypeAttributesDefaultDescription
elasticityNumber<optional>
objectDefaultElasticity

How bouncy the object is when colliding (0-1)

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

friction

Properties
NameTypeAttributesDefaultDescription
frictionNumber<optional>
objectDefaultFriction

How much friction to apply when sliding (0-1)

gravityScale

Properties
TypeDescription
Number

How much does gravity effect particles

isSolid

Properties
TypeDescription
Boolean

Object collides with and blocks other objects

localAngle

Properties
TypeDescription
Number

Local angle if child

localPos

Properties
TypeDescription
Vector2

Local position if child

localSpace

Properties
TypeDescription
Boolean

Should it be in local space of emitter

mass

Properties
NameTypeAttributesDefaultDescription
massNumber<optional>
objectDefaultMass

How heavy the object is, static if 0

mirror

Properties
TypeDescription
Boolean

Should it flip along y axis when rendered

parent

Properties
TypeDescription
EngineObject

Parent of object if in local space

particleConeAngle

Properties
TypeDescription
Number

Cone for start particle angle

particleCreateCallback

Properties
TypeDescription
function

Callback when particle is created

particleDestroyCallback

Properties
TypeDescription
function

Callback when particle is destroyed

particleTime

Properties
TypeDescription
Number

How long particles live

pos

Properties
TypeDescription
Vector2

World space position of the object

randomColorLinear

Properties
TypeDescription
Boolean

Should color be randomized linearly or across each component

randomness

Properties
TypeDescription
Number

Apply extra randomness percent

renderOrder

Properties
TypeDescription
Number

Objects are sorted by render order

size

Properties
TypeDescription
Vector2

World space width and height of the object

sizeEnd

Properties
TypeDescription
Number

How big are particles at end

sizeStart

Properties
TypeDescription
Number

How big are particles at start

spawnTime

Properties
TypeDescription
Number

Track when object was created

speed

Properties
TypeDescription
Number

How fast are particles when spawned

tileInfo

Properties
TypeDescription
TileInfo

Tile info to render object (undefined is untextured)

trailScale

Properties
TypeDescription
Number

If non zero the partile is drawn as a trail, stretched in the drection of velocity

velocity

Properties
TypeDescription
Vector2

Velocity of the object

Methods

addChild(child, localPosopt, localAngleopt)

Attaches a child to this with a given local transform

Parameters:
NameTypeAttributesDefaultDescription
childEngineObject
localPosVector2<optional>
(0,0)
localAngleNumber<optional>
0

applyAcceleration(acceleration)

Apply acceleration to this object (adjust velocity, not affected by mass)

Parameters:
NameTypeDescription
accelerationVector2

applyForce(force)

Apply force to this object (adjust velocity, affected by mass)

Parameters:
NameTypeDescription
forceVector2

collideWithObject(object) → {Boolean}

Called to check if a object collision should be resolved

Parameters:
NameTypeDescription
objectEngineObject

the object to test against

Returns:
  • true if the collision should be resolved
Type: 
Boolean

collideWithTile(tileData, pos) → {Boolean}

Called to check if a tile collision should be resolved

Parameters:
NameTypeDescription
tileDataNumber

the value of the tile at the position

posVector2

tile where the collision occured

Returns:
  • true if the collision should be resolved
Type: 
Boolean

destroy()

Destroy this object, destroy it's children, detach it's parent, and mark it for removal

emitParticle() → {Particle}

Spawn one particle

Returns:
Type: 
Particle

getAliveTime() → {Number}

How long since the object was created

Returns:
Type: 
Number

getMirrorSign() → {Number}

Get the direction of the mirror

Returns:

-1 if this.mirror is true, or 1 if not mirrored

Type: 
Number

localToWorld(pos)

Convert from local space to world space

Parameters:
NameTypeDescription
posVector2

local space point

localToWorldVector(vec)

Convert from local space to world space for a vector (rotation only)

Parameters:
NameTypeDescription
vecVector2

local space vector

removeChild(child)

Removes a child from this one

Parameters:
NameTypeDescription
childEngineObject

render()

Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder

renderDebugInfo()

Render debug info for this object

setCollision(collideSolidObjectsopt, isSolidopt, collideTilesopt, collideRaycastopt)

Set how this object collides

Parameters:
NameTypeAttributesDefaultDescription
collideSolidObjectsBoolean<optional>
true

Does it collide with solid objects?

isSolidBoolean<optional>
true

Does it collide with and block other objects? (expensive in large numbers)

collideTilesBoolean<optional>
true

Does it collide with the tile collision?

collideRaycastBoolean<optional>
true

Does it collide with raycasts?

toString() → {String}

Returns string containg info about this object for debugging

Returns:
Type: 
String

update()

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

updateTransforms()

Update the object transform, called automatically by engine even when paused

worldToLocal(pos)

Convert from world space to local space

Parameters:
NameTypeDescription
posVector2

world space point

worldToLocalVector(vec)

Convert from world space to local space for a vector (rotation only)

Parameters:
NameTypeDescription
vecVector2

world space vector