ParticleEmitter
Descriptionβ
This component makes an entity emit particles.
Propertiesβ
Property | Type | Default | Description |
---|---|---|---|
stopped | boolean | false | Playback state of the emitter |
emitterLife | number | 0 | The lifetime of the emitter in seconds |
particlesPerShot | integer | 20 | Particles per emission |
emitDelay | number | 0.1 | The time between particle emissions |
minimumLifespan | number | 1 | Minimum lifetime range for each particle |
maximumLifespan | number | 1 | Maximum lifetime range for each particle |
mass | number | 1 | Mass of each particle |
gravity | number | 0.2 | Gravity factor of each particle |
scale | number | 0.2 | Uniform scale of each particle |
forceX | number | 5 | Force applied to each particle in the X direction |
forceY | number | 12 | Force applied to each particle in the Y direction |
forceZ | number | 5 | Force applied to each particle in the Z direction |
spread | number | 360 | Area and direction that each particles spawns relative to its origin |
radialVelocity | number | 5 | Amount of radial velocity applied to each particle |
spawnAreaType | string | 'point' | Supported types are: 'point', 'box' and 'sphere' |
spawnAreaWidth | number | 0 | Width of the spawn area box (Box only) |
spawnAreaHeight | number | 0 | Height of the spawn area box (Box only) |
spawnAreaDepth | number | 0 | Depth of the spawn area box (Box only) |
spawnAreaRadius | number | 0 | Radius of the spawn area sphere (Sphere only) |
boundingZoneType | string | 'none' | Supported types are: 'none', 'box', 'sphere' |
boundingZoneWidth | number | 0 | Width of the bounding zone (Box only) |
boundingZoneHeight | number | 0 | Height of the bounding zone (Box only) |
boundingZoneDepth | number | 0 | Depth of the bounding zone (Box only) |
boundingZoneRadius | number | 0 | Radius of the bounding zone (Sphere only) |
resourceType | string | 'sprite' | Supported types are: 'sprite', and 'model' |
resourceUrl | string (URL) | '' | URL of the resource |
blendingMode | string | 'none' | Supported types are: 'none', 'normal', 'add', 'multiply' and 'subtract' |
animateColor | boolean | false | Determines if color should be animated |
colorStart | string (Hex) | undefined | The starting color of each particle |
colorEnd | string (Hex) | undefined | The ending color of each particle |
randomDrift | boolean | false | Enable randomized drifting for each particle |
randomDriftRange | number | undefined | Determines the randomized drift range and speed of each particle |
collisions | boolean | false | Determines if particles should respond to physics collisions |
Functionsβ
Getβ
Returns a read-only reference.
Example
ecs.ParticleEmitter.get(world, component.eid)
Setβ
Ensures the component exists on the entity, then assigns the (optional) data to the component.
Example
ecs.ParticleEmitter.set(world, component.eid, {
stopped: false,
emitterLife: 0,
particlesPerShot: 20,
emitDelay: 0.1,
minimumLifespan: 1,
maximumLifespan: 1,
mass: 1,
gravity: 0.2,
scale: 0.2,
forceX: 5,
forceY: 12,
forceZ: 5,
spread: 360
})
Mutateβ
Perform an update to the component within a callback function. Return true
to indicate no changes made.
Example
ecs.ParticleEmitter.mutate(world, component.eid, (cursor) => {
cursor.emitDelay = 0.05;
cursor.particlesPerShot = 50;
return false;
})
Removeβ
Removes the component from the entity.
Example
ecs.ParticleEmitter.remove(world, component.eid)
Hasβ
Returns true
if the component is present on the entity.
Example
ecs.ParticleEmitter.has(world, component.eid)
Resetβ
Adds, or resets the component to its default state.
Example
ecs.ParticleEmitter.reset(world, component.eid)
Advanced Functionsβ
Cursorβ
Returns a mutable reference. Cursors are reused so only one cursor for each component can exist at a time.
Example
ecs.ParticleEmitter.cursor(world, component.eid)
Acquireβ
Same behavior as cursor, but commit must be called after the cursor is done being used.
Example
ecs.ParticleEmitter.acquire(world, component.eid)
Commitβ
Called after acquire. An optional third argument determines whether the cursor was mutated or not.
Example
ecs.ParticleEmitter.commit(world, component.eid)
ecs.ParticleEmitter.commit(world, component.eid, false)
Dirtyβ
Mark the entity as having been mutated. Only needed in a specific case where systems are mutating data.
Example
ecs.ParticleEmitter.dirty(world, component.eid)