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
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
position | Vector2 | World space position of the emitter | ||
angle | Number | <optional> | Angle to emit the particles | |
emitSize | Number | | <optional> | 0 | World space size of the emitter (float for circle diameter, vec2 for rect) |
emitTime | Number | <optional> | 0 | How long to stay alive (0 is forever) |
emitRate | Number | <optional> | 100 | How many particles per second to spawn, does not emit if 0 |
emitConeAngle | Number | <optional> | PI | Local angle to apply velocity to particles from emitter |
tileInfo | TileInfo | <optional> | Tile info to render particles (undefined is untextured) | |
colorStartA | Color | <optional> | (1,1,1,1) | Color at start of life 1, randomized between start colors |
colorStartB | Color | <optional> | (1,1,1,1) | Color at start of life 2, randomized between start colors |
colorEndA | Color | <optional> | (1,1,1,0) | Color at end of life 1, randomized between end colors |
colorEndB | Color | <optional> | (1,1,1,0) | Color at end of life 2, randomized between end colors |
particleTime | Number | <optional> | 0.5 | How long particles live |
sizeStart | Number | <optional> | 0.1 | How big are particles at start |
sizeEnd | Number | <optional> | 1 | How big are particles at end |
speed | Number | <optional> | 0.1 | How fast are particles when spawned |
angleSpeed | Number | <optional> | 0.05 | How fast are particles rotating |
damping | Number | <optional> | 1 | How much to dampen particle speed |
angleDamping | Number | <optional> | 1 | How much to dampen particle angular speed |
gravityScale | Number | <optional> | 0 | How much gravity effect particles |
particleConeAngle | Number | <optional> | Cone for start particle angle | |
fadeRate | Number | <optional> | 0.1 | How quick to fade particles at start/end in percent of life |
randomness | Number | <optional> | 0.2 | Apply extra randomness percent |
collideTiles | Boolean | <optional> | false | Do particles collide against tiles |
additive | Boolean | <optional> | false | Should particles use addtive blend |
randomColorLinear | Boolean | <optional> | 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> | false | Should it be in local space of emitter (world space is default) |
- Source
// 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
PropertiesType | Description |
---|---|
Boolean | Should particles use addtive blend |
- Source
additiveColor
PropertiesType | Description |
---|---|
Color | Additive color to apply when rendered |
- Overrides
- Source
angle
PropertiesType | Description |
---|---|
Number | Angle to rotate the object |
- Overrides
- Source
angleDamping
PropertiesType | Description |
---|---|
Number | How much to dampen particle angular speed |
- Overrides
- Source
angleSpeed
PropertiesType | Description |
---|---|
Number | How fast are particles rotating |
- Source
angleVelocity
PropertiesType | Description |
---|---|
Number | Angular velocity of the object |
- Overrides
- Source
children
PropertiesType | Description |
---|---|
Array | List of children of this object |
- Overrides
- Source
clampSpeedLinear
PropertiesType | Description |
---|---|
Boolean | Limit object speed using linear or circular math |
- Overrides
- Source
collideRaycast
PropertiesType | Description |
---|---|
Boolean | Object collides with raycasts |
- Overrides
- Source
collideSolidObjects
PropertiesType | Description |
---|---|
Boolean | Object collides with solid objects |
- Overrides
- Source
collideTiles
PropertiesType | Description |
---|---|
Boolean | Do particles collide against tiles |
- Overrides
- Source
color
PropertiesType | Description |
---|---|
Color | Color to apply when rendered |
- Overrides
- Source
colorEndA
PropertiesType | Description |
---|---|
Color | Color at end of life 1, randomized between end colors |
- Source
colorEndB
PropertiesType | Description |
---|---|
Color | Color at end of life 2, randomized between end colors |
- Source
colorStartA
PropertiesType | Description |
---|---|
Color | Color at start of life 1, randomized between start colors |
- Source
colorStartB
PropertiesType | Description |
---|---|
Color | Color at start of life 2, randomized between start colors |
- Source
damping
PropertiesType | Description |
---|---|
Number | How much to dampen particle speed |
- Overrides
- Source
drawSize
PropertiesType | Description |
---|---|
Vector2 | Size of object used for drawing, uses size if not set |
- Overrides
- Source
elasticity
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
elasticity | Number | <optional> | objectDefaultElasticity | How bouncy the object is when colliding (0-1) |
- Overrides
- Source
emitConeAngle
PropertiesType | Description |
---|---|
Number | Local angle to apply velocity to particles from emitter |
- Source
emitRate
PropertiesType | Description |
---|---|
Number | How many particles per second to spawn, does not emit if 0 |
- Source
emitSize
PropertiesType | Description |
---|---|
Number | | World space size of the emitter (float for circle diameter, vec2 for rect) |
- Source
emitTime
PropertiesType | Description |
---|---|
Number | How long to stay alive (0 is forever) |
- Source
emitTimeBuffer
PropertiesType | Description |
---|---|
Number | Track particle emit time |
- Source
fadeRate
PropertiesType | Description |
---|---|
Number | How quick to fade in particles at start/end in percent of life |
- Source
friction
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
friction | Number | <optional> | objectDefaultFriction | How much friction to apply when sliding (0-1) |
- Overrides
- Source
gravityScale
PropertiesType | Description |
---|---|
Number | How much does gravity effect particles |
- Overrides
- Source
isSolid
PropertiesType | Description |
---|---|
Boolean | Object collides with and blocks other objects |
- Overrides
- Source
localAngle
PropertiesType | Description |
---|---|
Number | Local angle if child |
- Overrides
- Source
localPos
PropertiesType | Description |
---|---|
Vector2 | Local position if child |
- Overrides
- Source
localSpace
PropertiesType | Description |
---|---|
Boolean | Should it be in local space of emitter |
- Source
mass
PropertiesName | Type | Attributes | Default | Description |
---|---|---|---|---|
mass | Number | <optional> | objectDefaultMass | How heavy the object is, static if 0 |
- Overrides
- Source
mirror
PropertiesType | Description |
---|---|
Boolean | Should it flip along y axis when rendered |
- Overrides
- Source
parent
PropertiesType | Description |
---|---|
EngineObject | Parent of object if in local space |
- Overrides
- Source
particleConeAngle
PropertiesType | Description |
---|---|
Number | Cone for start particle angle |
- Source
particleCreateCallback
PropertiesType | Description |
---|---|
function | Callback when particle is created |
- Source
particleDestroyCallback
PropertiesType | Description |
---|---|
function | Callback when particle is destroyed |
- Source
particleTime
PropertiesType | Description |
---|---|
Number | How long particles live |
- Source
pos
PropertiesType | Description |
---|---|
Vector2 | World space position of the object |
- Overrides
- Source
randomColorLinear
PropertiesType | Description |
---|---|
Boolean | Should color be randomized linearly or across each component |
- Source
randomness
PropertiesType | Description |
---|---|
Number | Apply extra randomness percent |
- Source
renderOrder
PropertiesType | Description |
---|---|
Number | Objects are sorted by render order |
- Overrides
- Source
size
PropertiesType | Description |
---|---|
Vector2 | World space width and height of the object |
- Overrides
- Source
sizeEnd
PropertiesType | Description |
---|---|
Number | How big are particles at end |
- Source
sizeStart
PropertiesType | Description |
---|---|
Number | How big are particles at start |
- Source
spawnTime
PropertiesType | Description |
---|---|
Number | Track when object was created |
- Overrides
- Source
speed
PropertiesType | Description |
---|---|
Number | How fast are particles when spawned |
- Source
tileInfo
PropertiesType | Description |
---|---|
TileInfo | Tile info to render object (undefined is untextured) |
- Overrides
- Source
trailScale
PropertiesType | Description |
---|---|
Number | If non zero the partile is drawn as a trail, stretched in the drection of velocity |
- Source
velocity
PropertiesType | Description |
---|---|
Vector2 | Velocity of the object |
- Overrides
- Source
Methods
addChild(child, localPosopt, localAngleopt)
Attaches a child to this with a given local transform
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child | EngineObject | |||
localPos | Vector2 | <optional> | (0,0) | |
localAngle | Number | <optional> | 0 |
- Overrides
- Source
applyAcceleration(acceleration)
Apply acceleration to this object (adjust velocity, not affected by mass)
Name | Type | Description |
---|---|---|
acceleration | Vector2 |
- Overrides
- Source
applyForce(force)
Apply force to this object (adjust velocity, affected by mass)
Name | Type | Description |
---|---|---|
force | Vector2 |
- Overrides
- Source
collideWithObject(object) → {Boolean}
Called to check if a object collision should be resolved
Name | Type | Description |
---|---|---|
object | EngineObject | the object to test against |
- Overrides
- Source
- true if the collision should be resolved
- Type:
- Boolean
collideWithTile(tileData, pos) → {Boolean}
Called to check if a tile collision should be resolved
Name | Type | Description |
---|---|---|
tileData | Number | the value of the tile at the position |
pos | Vector2 | tile where the collision occured |
- Overrides
- Source
- 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
- Overrides
- Source
emitParticle() → {Particle}
Spawn one particle
- Source
- Type:
- Particle
getAliveTime() → {Number}
How long since the object was created
- Overrides
- Source
- Type:
- Number
getMirrorSign() → {Number}
Get the direction of the mirror
- Overrides
- Source
-1 if this.mirror is true, or 1 if not mirrored
- Type:
- Number
localToWorld(pos)
Convert from local space to world space
Name | Type | Description |
---|---|---|
pos | Vector2 | local space point |
- Overrides
- Source
localToWorldVector(vec)
Convert from local space to world space for a vector (rotation only)
Name | Type | Description |
---|---|---|
vec | Vector2 | local space vector |
- Overrides
- Source
removeChild(child)
Removes a child from this one
Name | Type | Description |
---|---|---|
child | EngineObject |
- Overrides
- Source
render()
Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder
- Overrides
- Source
renderDebugInfo()
Render debug info for this object
- Overrides
- Source
setCollision(collideSolidObjectsopt, isSolidopt, collideTilesopt, collideRaycastopt)
Set how this object collides
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
collideSolidObjects | Boolean | <optional> | true | Does it collide with solid objects? |
isSolid | Boolean | <optional> | true | Does it collide with and block other objects? (expensive in large numbers) |
collideTiles | Boolean | <optional> | true | Does it collide with the tile collision? |
collideRaycast | Boolean | <optional> | true | Does it collide with raycasts? |
- Overrides
- Source
toString() → {String}
Returns string containg info about this object for debugging
- Overrides
- Source
- Type:
- String
update()
Update the emitter to spawn particles, called automatically by engine once each frame
- Overrides
- Source
updateTransforms()
Update the object transform, called automatically by engine even when paused
- Overrides
- Source
worldToLocal(pos)
Convert from world space to local space
Name | Type | Description |
---|---|---|
pos | Vector2 | world space point |
- Overrides
- Source
worldToLocalVector(vec)
Convert from world space to local space for a vector (rotation only)
Name | Type | Description |
---|---|---|
vec | Vector2 | world space vector |
- Overrides
- Source