Constructor
# new ParticleEmitter(position, angleopt, emitSizeopt, emitTimeopt, emitRateopt, emitConeAngleopt, tileIndexopt, tileSizeopt, colorStartAopt, colorStartBopt, colorEndAopt, colorEndBopt, particleTimeopt, sizeStartopt, sizeEndopt, speedopt, angleSpeedopt, dampingopt, angleDampingopt, gravityScaleopt, particleConeAngleopt, fadeRateopt, randomnessopt, collideTilesopt, additiveopt, randomColorLinearopt, renderOrderopt)
Create a particle system with the given settings
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
position |
Vector2 | World space position of the emitter | ||
angle |
Number |
<optional> |
0 | 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 |
tileIndex |
Number |
<optional> |
-1 | Index into tile sheet, if <0 no texture is applied |
tileSize |
Number |
<optional> |
tileSizeDefault | Tile size for particles |
colorStartA |
Color |
<optional> |
new Color(1,1,1) | Color at start of life 1, randomized between start colors |
colorStartB |
Color |
<optional> |
new Color(1,1,1) | Color at start of life 2, randomized between start colors |
colorEndA |
Color |
<optional> |
new Color(1,1,1,0) | Color at end of life 1, randomized between end colors |
colorEndB |
Color |
<optional> |
new Color(1,1,1,0) | Color at end of life 2, randomized between end colors |
particleTime |
Number |
<optional> |
.5 | How long particles live |
sizeStart |
Number |
<optional> |
.1 | How big are particles at start |
sizeEnd |
Number |
<optional> |
1 | How big are particles at end |
speed |
Number |
<optional> |
.1 | How fast are particles when spawned |
angleSpeed |
Number |
<optional> |
.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 does gravity effect particles |
particleConeAngle |
Number |
<optional> |
PI | Cone for start particle angle |
fadeRate |
Number |
<optional> |
.1 | How quick to fade in particles at start/end in percent of life |
randomness |
Number |
<optional> |
.2 | Apply extra randomness percent |
collideTiles |
Boolean |
<optional> |
0 | Do particles collide against tiles |
additive |
Boolean |
<optional> |
0 | Should particles use addtive blend |
randomColorLinear |
Boolean |
<optional> |
1 | Should color be randomized linearly or across each component |
renderOrder |
Number |
<optional> |
0 | Render order for particles (additive is above other stuff by default) |
- Source:
Example
// create a particle emitter
let pos = vec2(2,3);
let particleEmiter = new ParticleEmitter
(
pos, 0, 1, 0, 500, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
0, vec2(16), // tileIndex, tileSize
new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
new Color(1,1,1,0), new Color(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
Type | Description |
---|---|
Number | Should particles use addtive blend |
- Source:
# additiveColor
Properties
Type | Description |
---|---|
Color | Additive color to apply when rendered |
- Overrides:
- Source:
# angle
Properties
Type | Description |
---|---|
Number | Angle to rotate the object |
- Overrides:
- Source:
# angleDamping
Properties
Type | Description |
---|---|
Number | How much to dampen particle angular speed |
- Overrides:
- Source:
# angleSpeed
Properties
Type | Description |
---|---|
Number | How fast are particles rotating |
- Source:
# angleVelocity
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
angleVelocity |
Number |
<optional> |
0 | Angular velocity of the object |
- Overrides:
- Source:
# collideTiles
Properties
Type | Description |
---|---|
Number | Do particles collide against tiles |
- Source:
# color
Properties
Type | Description |
---|---|
Color | Color to apply when rendered |
- Overrides:
- Source:
# colorEndA
Properties
Type | Description |
---|---|
Color | Color at end of life 1, randomized between end colors |
- Source:
# colorEndB
Properties
Type | Description |
---|---|
Color | Color at end of life 2, randomized between end colors |
- Source:
# colorStartA
Properties
Type | Description |
---|---|
Color | Color at start of life 1, randomized between start colors |
- Source:
# colorStartB
Properties
Type | Description |
---|---|
Color | Color at start of life 2, randomized between start colors |
- Source:
# damping
Properties
Type | Description |
---|---|
Number | How much to dampen particle speed |
- Overrides:
- Source:
# drawSize
Properties
Type | Description |
---|---|
Vector2 | Size of object used for drawing, uses size if not set |
- Overrides:
- Source:
# elasticity
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
elasticity |
Number |
<optional> |
objectDefaultElasticity | How bouncy the object is when colliding (0-1) |
- Overrides:
- Source:
# emitConeAngle
Properties
Type | Description |
---|---|
Number | Local angle to apply velocity to particles from emitter |
- Source:
# emitRate
Properties
Type | Description |
---|---|
Number | How many particles per second to spawn, does not emit if 0 |
- Source:
# emitSize
Properties
Type | Description |
---|---|
Number | World space size of the emitter (float for circle diameter, vec2 for rect) |
- Source:
# emitTime
Properties
Type | Description |
---|---|
Number | How long to stay alive (0 is forever) |
- Source:
# fadeRate
Properties
Type | Description |
---|---|
Number | How quick to fade in particles at start/end in percent of life |
- Source:
# friction
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
friction |
Number |
<optional> |
objectDefaultFriction | How much friction to apply when sliding (0-1) |
- Overrides:
- Source:
# gravityScale
Properties
Type | Description |
---|---|
Number | How much does gravity effect particles |
- Overrides:
- Source:
# mass
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
mass |
Number |
<optional> |
objectDefaultMass | How heavy the object is |
- Overrides:
- Source:
# particleConeAngle
Properties
Type | Description |
---|---|
Number | Cone for start particle angle |
- Source:
# particleTime
Properties
Type | Description |
---|---|
Number | How long particles live |
- Source:
# pos
Properties
Type | Description |
---|---|
Vector2 | World space position of the object |
- Overrides:
- Source:
# randomColorLinear
Properties
Type | Description |
---|---|
Boolean | Should color be randomized linearly or across each component |
- Source:
# randomness
Properties
Type | Description |
---|---|
Number | Apply extra randomness percent |
- Source:
# renderOrder
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
renderOrder |
Number |
<optional> |
0 | Objects are sorted by render order |
- Overrides:
- Source:
# size
Properties
Type | Description |
---|---|
Vector2 | World space width and height of the object |
- Overrides:
- Source:
# sizeEnd
Properties
Type | Description |
---|---|
Number | How big are particles at end |
- Source:
# sizeStart
Properties
Type | Description |
---|---|
Number | How big are particles at start |
- Source:
# speed
Properties
Type | Description |
---|---|
Number | How fast are particles when spawned |
- Source:
# tileIndex
Properties
Type | Description |
---|---|
Number | Tile to use to render object, untextured if -1 |
- Overrides:
- Source:
# tileSize
Properties
Type | Description |
---|---|
Vector2 | Size of tile in source pixels |
- Overrides:
- Source:
# trailScale
Properties
Type | Description |
---|---|
Number | If set the partile is drawn as a trail, stretched in the drection of velocity |
- Source:
# velocity
Properties
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
velocity |
Vector2 |
<optional> |
new Vector2() | Velocity of the object |
- Overrides:
- Source:
Methods
# addChild(child, localPosopt, localAngleopt)
Attaches a child to this with a given local transform
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
child |
EngineObject | |||
localPos |
Vector2 |
<optional> |
new Vector2 | |
localAngle |
Number |
<optional> |
0 |
- Overrides:
- Source:
# applyAcceleration(acceleration)
Apply acceleration to this object (adjust velocity, not affected by mass)
Parameters:
Name | Type | Description |
---|---|---|
acceleration |
Vector2 |
- Overrides:
- Source:
# applyForce(force)
Apply force to this object (adjust velocity, affected by mass)
Parameters:
Name | Type | Description |
---|---|---|
force |
Vector2 |
- Overrides:
- Source:
# collideWithObject(object) → {Boolean}
Called to check if a tile raycast hit
Parameters:
Name | Type | Description |
---|---|---|
object |
EngineObject | the object to test against |
- Overrides:
- Source:
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:
Name | Type | Description |
---|---|---|
tileData |
Number | the value of the tile at the position |
pos |
Vector2 | tile where the collision occured |
- Overrides:
- Source:
Returns:
- true if the collision should be resolved
- Type
- Boolean
# collideWithTileRaycast(tileData, pos) → {Boolean}
Called to check if a tile raycast hit
Parameters:
Name | Type | Description |
---|---|---|
tileData |
Number | the value of the tile at the position |
pos |
Vector2 | tile where the raycast is |
- Overrides:
- Source:
Returns:
- true if the raycast should hit
- 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:
Returns:
- Type
- Particle
# getAliveTime() → {Number}
How long since the object was created
- Overrides:
- Source:
Returns:
- Type
- Number
# getMirrorSign() → {Number}
Get the direction of the mirror
- Overrides:
- Source:
Returns:
-1 if this.mirror is true, or 1 if not mirrored
- Type
- Number
# removeChild(child)
Removes a child from this one
Parameters:
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:
# setCollision(collideSolidObjectsopt, isSolidopt, collideTilesopt)
Set how this object collides
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
collideSolidObjects |
boolean |
<optional> |
0 | Does it collide with solid objects |
isSolid |
boolean |
<optional> |
0 | Does it collide with and block other objects (expensive in large numbers) |
collideTiles |
boolean |
<optional> |
1 | Does it collide with the tile collision |
- Overrides:
- Source:
# update()
Update the emitter to spawn particles, called automatically by engine once each frame
- Overrides:
- Source: