
Mirror Engine API / ParticleSystemComponent
Class: ParticleSystemComponent
Used to simulate particles and produce renderable particle mesh on either CPU or GPU. GPU simulation is generally much faster than its CPU counterpart, because it avoids slow CPU-GPU synchronization and takes advantage of many GPU cores. However, it requires client to support reasonable uniform count, reading from multiple textures in vertex shader and OES_texture_float extension, including rendering into float textures. Most mobile devices fail to satisfy these requirements, so it's not recommended to simulate thousands of particles on them. GPU version also can't sort particles, so enabling sorting forces CPU mode too. Particle rotation is specified by a single angle parameter: default billboard particles rotate around camera facing axis, while mesh particles rotate around 2 different view-independent axes. Most of the simulation parameters are specified with Curve or CurveSet. Curves are interpolated based on each particle's lifetime, therefore parameters are able to change over time. Most of the curve parameters can also be specified by 2 minimum/maximum curves, this way each particle will pick a random value in-between.
Extends
Component
Properties
entity
entity: Entity
The Entity that this Component is attached to.
Inherited from
Component.entity
system
system: ComponentSystem
The ComponentSystem used to create this Component.
Inherited from
Component.system
alignToMotion
Get Signature
get alignToMotion(): boolean
Gets whether particles are oriented in their direction of motion or not.
Returns
boolean
Set Signature
set alignToMotion(arg: boolean): void
Sets whether particles are oriented in their direction of motion or not.
Parameters
arg
boolean
Returns
void
alphaGraph
Get Signature
get alphaGraph(): Curve
Gets the alpha graph.
Returns
Set Signature
set alphaGraph(arg: Curve): void
Sets the alpha graph.
Parameters
arg
Returns
void
alphaGraph2
Get Signature
get alphaGraph2(): Curve
Gets the second alpha graph.
Returns
Set Signature
set alphaGraph2(arg: Curve): void
Sets the second alpha graph. If not null, particles pick random values between alphaGraph
and alphaGraph2
.
Parameters
arg
Returns
void
animIndex
Get Signature
get animIndex(): number
Gets the index of the animation to play.
Returns
number
Set Signature
set animIndex(arg: number): void
Sets the index of the animation to play. When animNumAnimations
is greater than 1, the
sprite sheet animation index determines which animation the particle system should play.
Parameters
arg
number
Returns
void
animLoop
Get Signature
get animLoop(): boolean
Gets whether the sprite sheet animation plays once or loops continuously.
Returns
boolean
Set Signature
set animLoop(arg: boolean): void
Sets whether the sprite sheet animation plays once or loops continuously.
Parameters
arg
boolean
Returns
void
animNumAnimations
Get Signature
get animNumAnimations(): number
Gets the number of sprite sheet animations contained within the current sprite sheet.
Returns
number
Set Signature
set animNumAnimations(arg: number): void
Sets the number of sprite sheet animations contained within the current sprite sheet. The
number of animations multiplied by number of frames should be a value less than animTilesX
multiplied by animTilesY
.
Parameters
arg
number
Returns
void
animNumFrames
Get Signature
get animNumFrames(): number
Gets the number of sprite sheet frames in the current sprite sheet animation.
Returns
number
Set Signature
set animNumFrames(arg: number): void
Sets the number of sprite sheet frames in the current sprite sheet animation. The number of
animations multiplied by number of frames should be a value less than animTilesX
multiplied by animTilesY
.
Parameters
arg
number
Returns
void
animSpeed
Get Signature
get animSpeed(): number
Gets the sprite sheet animation speed.
Returns
number
Set Signature
set animSpeed(arg: number): void
Sets the sprite sheet animation speed. 1 = particle lifetime, 2 = double the particle lifetime, etc.
Parameters
arg
number
Returns
void
animStartFrame
Get Signature
get animStartFrame(): number
Gets the sprite sheet frame that the animation should begin playing from.
Returns
number
Set Signature
set animStartFrame(arg: number): void
Sets the sprite sheet frame that the animation should begin playing from. Indexed from the start of the current animation.
Parameters
arg
number
Returns
void
animTilesX
Get Signature
get animTilesX(): number
Gets the number of horizontal tiles in the sprite sheet.
Returns
number
Set Signature
set animTilesX(arg: number): void
Sets the number of horizontal tiles in the sprite sheet.
Parameters
arg
number
Returns
void
animTilesY
Get Signature
get animTilesY(): number
Gets the number of vertical tiles in the sprite sheet.
Returns
number
Set Signature
set animTilesY(arg: number): void
Sets the number of vertical tiles in the sprite sheet.
Parameters
arg
number
Returns
void
autoPlay
Get Signature
get autoPlay(): boolean
Gets whether the particle system plays automatically on creation.
Returns
boolean
Set Signature
set autoPlay(arg: boolean): void
Sets whether the particle system plays automatically on creation. If set to false, it is necessary to call ParticleSystemComponent#play for the particle system to play. Defaults to true.
Parameters
arg
boolean
Returns
void
blendType
Get Signature
get blendType(): number
Gets how particles are blended when being written to the currently active render target.
Returns
number
Set Signature
set blendType(arg: number): void
Sets how particles are blended when being written to the currently active render target. Can be:
- BLEND_SUBTRACTIVE: Subtract the color of the source fragment from the destination fragment and write the result to the frame buffer.
- BLEND_ADDITIVE: Add the color of the source fragment to the destination fragment and write the result to the frame buffer.
- BLEND_NORMAL: Enable simple translucency for materials such as glass. This is equivalent to enabling a source blend mode of BLENDMODE_SRC_ALPHA and a destination blend mode of BLENDMODE_ONE_MINUS_SRC_ALPHA.
- BLEND_NONE: Disable blending.
- BLEND_PREMULTIPLIED: Similar to BLEND_NORMAL expect the source fragment is assumed to have already been multiplied by the source alpha value.
- BLEND_MULTIPLICATIVE: Multiply the color of the source fragment by the color of the destination fragment and write the result to the frame buffer.
- BLEND_ADDITIVEALPHA: Same as BLEND_ADDITIVE except the source RGB is multiplied by the source alpha.
Parameters
arg
number
Returns
void
colorGraph
Get Signature
get colorGraph(): CurveSet
Gets the color graph.
Returns
Set Signature
set colorGraph(arg: CurveSet): void
Sets the color graph.
Parameters
arg
Returns
void
colorGraph2
Get Signature
get colorGraph2(): CurveSet
Gets the second color graph.
Returns
Set Signature
set colorGraph2(arg: CurveSet): void
Sets the second color graph. If not null, particles pick random values between colorGraph
and colorGraph2
.
Parameters
arg
Returns
void
colorMap
Get Signature
get colorMap(): Texture
Gets the color map texture to apply to all particles in the system.
Returns
Set Signature
set colorMap(arg: Texture): void
Sets the color map texture to apply to all particles in the system. If no texture is assigned, a default spot texture is used.
Parameters
arg
Returns
void
colorMapAsset
Get Signature
get colorMapAsset(): Asset
Gets the Asset used to set the colorMap.
Returns
Set Signature
set colorMapAsset(arg: Asset): void
Sets the Asset used to set the colorMap.
Parameters
arg
Returns
void
depthSoftening
Get Signature
get depthSoftening(): number
Gets whether depth softening is enabled.
Returns
number
Set Signature
set depthSoftening(arg: number): void
Sets whether depth softening is enabled. Controls fading of particles near their intersections with scene geometry. This effect, when it's non-zero, requires scene depth map to be rendered. Multiple depth-dependent effects can share the same map, but if you only use it for particles, bear in mind that it can double engine draw calls.
Parameters
arg
number
Returns
void
depthWrite
Get Signature
get depthWrite(): boolean
Gets whether depth writes is enabled.
Returns
boolean
Set Signature
set depthWrite(arg: boolean): void
Sets whether depth writes is enabled. If enabled, the particles will write to the depth buffer. If disabled, the depth buffer is left unchanged and particles will be guaranteed to overwrite one another in the order in which they are rendered.
Parameters
arg
boolean
Returns
void
drawOrder
Get Signature
get drawOrder(): number
Gets the draw order of the component.
Returns
number
Set Signature
set drawOrder(drawOrder: number): void
Sets the draw order of the component. A higher value means that the component will be rendered on top of other components in the same layer. This is not used unless the layer's sort order is set to SORTMODE_MANUAL.
Parameters
drawOrder
number
Returns
void
emitterExtents
Get Signature
get emitterExtents(): Vec3
Gets the extents of a local space bounding box within which particles are spawned at random positions.
Returns
Set Signature
set emitterExtents(arg: Vec3): void
Sets the extents of a local space bounding box within which particles are spawned at random
positions. This only applies to particle system with the shape EMITTERSHAPE_BOX
.
Parameters
arg
Returns
void
emitterExtentsInner
Get Signature
get emitterExtentsInner(): Vec3
Gets the exception of extents of a local space bounding box within which particles are not spawned.
Returns
Set Signature
set emitterExtentsInner(arg: Vec3): void
Sets the exception of extents of a local space bounding box within which particles are not
spawned. It is aligned to the center of emitterExtents. This only applies to particle system
with the shape EMITTERSHAPE_BOX
.
Parameters
arg
Returns
void
emitterRadius
Get Signature
get emitterRadius(): number
Gets the radius within which particles are spawned at random positions.
Returns
number
Set Signature
set emitterRadius(arg: number): void
Sets the radius within which particles are spawned at random positions. This only applies to
particle system with the shape EMITTERSHAPE_SPHERE
.
Parameters
arg
number
Returns
void
emitterRadiusInner
Get Signature
get emitterRadiusInner(): number
Gets the inner radius within which particles are not spawned.
Returns
number
Set Signature
set emitterRadiusInner(arg: number): void
Sets the inner radius within which particles are not spawned. This only applies to particle
system with the shape EMITTERSHAPE_SPHERE
.
Parameters
arg
number
Returns
void
emitterShape
Get Signature
get emitterShape(): number
Gets the shape of the emitter.
Returns
number
Set Signature
set emitterShape(arg: number): void
Sets the shape of the emitter. Defines the bounds inside which particles are spawned. Also affects the direction of initial velocity.
- EMITTERSHAPE_BOX: Box shape parameterized by emitterExtents. Initial velocity is directed towards local Z axis.
- EMITTERSHAPE_SPHERE: Sphere shape parameterized by emitterRadius. Initial velocity is directed outwards from the center.
Parameters
arg
number
Returns
void
enabled
Get Signature
get enabled(): boolean
Gets the enabled state of the component.
Returns
boolean
Set Signature
set enabled(arg: boolean): void
Sets the enabled state of the component.
Parameters
arg
boolean
Returns
void
Overrides
Component.enabled
halfLambert
Get Signature
get halfLambert(): boolean
Gets whether Half Lambert lighting is enabled.
Returns
boolean
Set Signature
set halfLambert(arg: boolean): void
Sets whether Half Lambert lighting is enabled. Enabling Half Lambert lighting avoids particles looking too flat in shadowed areas. It is a completely non-physical lighting model but can give more pleasing visual results.
Parameters
arg
boolean
Returns
void
initialVelocity
Get Signature
get initialVelocity(): number
Gets the magnitude of the initial emitter velocity.
Returns
number
Set Signature
set initialVelocity(arg: number): void
Sets the magnitude of the initial emitter velocity. Direction is given by emitter shape.
Parameters
arg
number
Returns
void
intensity
Get Signature
get intensity(): number
Gets the color multiplier.
Returns
number
Set Signature
set intensity(arg: number): void
Sets the color multiplier.
Parameters
arg
number
Returns
void
layers
Get Signature
get layers(): number[]
Gets the array of layer IDs (Layer#id) to which this particle system belongs.
Returns
number
[]
Set Signature
set layers(arg: number[]): void
Sets the array of layer IDs (Layer#id) to which this particle system should belong. Don't push/pop/splice or modify this array. If you want to change it, set a new one instead.
Parameters
arg
number
[]
Returns
void
lifetime
Get Signature
get lifetime(): number
Gets the length of time in seconds between a particle's birth and its death.
Returns
number
Set Signature
set lifetime(arg: number): void
Sets the length of time in seconds between a particle's birth and its death.
Parameters
arg
number
Returns
void
lighting
Get Signature
get lighting(): boolean
Gets whether particles will be lit by ambient and directional lights.
Returns
boolean
Set Signature
set lighting(arg: boolean): void
Sets whether particles will be lit by ambient and directional lights.
Parameters
arg
boolean
Returns
void
localSpace
Get Signature
get localSpace(): boolean
Gets whether particles move with respect to the emitter's transform rather then world space.
Returns
boolean
Set Signature
set localSpace(arg: boolean): void
Sets whether particles move with respect to the emitter's transform rather then world space.
Parameters
arg
boolean
Returns
void
localVelocityGraph
Get Signature
get localVelocityGraph(): CurveSet
Gets the local space velocity graph.
Returns
Set Signature
set localVelocityGraph(arg: CurveSet): void
Sets the local space velocity graph.
Parameters
arg
Returns
void
localVelocityGraph2
Get Signature
get localVelocityGraph2(): CurveSet
Gets the second velocity graph.
Returns
Set Signature
set localVelocityGraph2(arg: CurveSet): void
Sets the second velocity graph. If not null, particles pick random values between localVelocityGraph and localVelocityGraph2.
Parameters
arg
Returns
void
loop
Get Signature
get loop(): boolean
Gets whether the particle system loops.
Returns
boolean
Set Signature
set loop(arg: boolean): void
Sets whether the particle system loops.
Parameters
arg
boolean
Returns
void
mesh
Get Signature
get mesh(): Mesh
Gets the polygonal mesh to be used as a particle.
Returns
Set Signature
set mesh(arg: Mesh): void
Sets the polygonal mesh to be used as a particle. Only first vertex/index buffer is used. Vertex buffer must contain local position at first 3 floats of each vertex.
Parameters
arg
Returns
void
meshAsset
Get Signature
get meshAsset(): Asset
Gets the Asset used to set the mesh.
Returns
Set Signature
set meshAsset(arg: Asset): void
Sets the Asset used to set the mesh.
Parameters
arg
Returns
void
noFog
Get Signature
get noFog(): boolean
Gets whether fogging is ignored.
Returns
boolean
Set Signature
set noFog(arg: boolean): void
Sets whether fogging is ignored.
Parameters
arg
boolean
Returns
void
normalMap
Get Signature
get normalMap(): Texture
Gets the normal map texture to apply to all particles in the system.
Returns
Set Signature
set normalMap(arg: Texture): void
Sets the normal map texture to apply to all particles in the system. If no texture is assigned, an approximate spherical normal is calculated for each vertex.
Parameters
arg
Returns
void
normalMapAsset
Get Signature
get normalMapAsset(): Asset
Gets the Asset used to set the normalMap.
Returns
Set Signature
set normalMapAsset(arg: Asset): void
Sets the Asset used to set the normalMap.
Parameters
arg
Returns
void
numParticles
Get Signature
get numParticles(): number
Gets the maximum number of simulated particles.
Returns
number
Set Signature
set numParticles(arg: number): void
Sets the maximum number of simulated particles.
Parameters
arg
number
Returns
void
orientation
Get Signature
get orientation(): number
Gets the particle orientation mode.
Returns
number
Set Signature
set orientation(arg: number): void
Sets the particle orientation mode. Can be:
- PARTICLEORIENTATION_SCREEN: Particles are facing camera.
- PARTICLEORIENTATION_WORLD: User defined world space normal (particleNormal) to set planes orientation.
- PARTICLEORIENTATION_EMITTER: Similar to previous, but the normal is affected by emitter (entity) transformation.
Parameters
arg
number
Returns
void
particleNormal
Get Signature
get particleNormal(): Vec3
Gets the particle normal.
Returns
Set Signature
set particleNormal(arg: Vec3): void
Sets the particle normal. This only applies to particle system with the orientation modes
PARTICLEORIENTATION_WORLD
and PARTICLEORIENTATION_EMITTER
.
Parameters
arg
Returns
void
preWarm
Get Signature
get preWarm(): boolean
Gets whether the particle system will be initialized as though it has already completed a full cycle.
Returns
boolean
Set Signature
set preWarm(arg: boolean): void
Sets whether the particle system will be initialized as though it has already completed a full cycle. This only works with looping particle systems.
Parameters
arg
boolean
Returns
void
radialSpeedGraph
Get Signature
get radialSpeedGraph(): Curve
Gets the radial speed graph.
Returns
Set Signature
set radialSpeedGraph(arg: Curve): void
Sets the radial speed graph. Velocity vector points from emitter origin to particle position.
Parameters
arg
Returns
void
radialSpeedGraph2
Get Signature
get radialSpeedGraph2(): Curve
Gets the second radial speed graph.
Returns
Set Signature
set radialSpeedGraph2(arg: Curve): void
Sets the second radial speed graph. If not null, particles pick random values between radialSpeedGraph and radialSpeedGraph2. Velocity vector points from emitter origin to particle position.
Parameters
arg
Returns
void
randomizeAnimIndex
Get Signature
get randomizeAnimIndex(): boolean
Gets whether each particle emitted by the system will play a random animation from the
sprite sheet, up to animNumAnimations
.
Returns
boolean
Set Signature
set randomizeAnimIndex(arg: boolean): void
Sets whether each particle emitted by the system will play a random animation from the
sprite sheet, up to animNumAnimations
.
Parameters
arg
boolean
Returns
void
rate
Get Signature
get rate(): number
Gets the minimal interval in seconds between particle births.
Returns
number
Set Signature
set rate(arg: number): void
Sets the minimal interval in seconds between particle births.
Parameters
arg
number
Returns
void
rate2
Get Signature
get rate2(): number
Gets the maximal interval in seconds between particle births.
Returns
number
Set Signature
set rate2(arg: number): void
Sets the maximal interval in seconds between particle births.
Parameters
arg
number
Returns
void
renderAsset
Get Signature
get renderAsset(): Asset
Gets the Render Asset used to set the mesh.
Returns
Set Signature
set renderAsset(arg: Asset): void
Sets the Render Asset used to set the mesh.
Parameters
arg
Returns
void
rotationSpeedGraph
Get Signature
get rotationSpeedGraph(): Curve
Gets the rotation speed graph.
Returns
Set Signature
set rotationSpeedGraph(arg: Curve): void
Sets the rotation speed graph.
Parameters
arg
Returns
void
rotationSpeedGraph2
Get Signature
get rotationSpeedGraph2(): Curve
Gets the second rotation speed graph.
Returns
Set Signature
set rotationSpeedGraph2(arg: Curve): void
Sets the second rotation speed graph. If not null, particles pick random values between rotationSpeedGraph and rotationSpeedGraph2.
Parameters
arg
Returns
void
scaleGraph
Get Signature
get scaleGraph(): Curve
Gets the scale graph.
Returns
Set Signature
set scaleGraph(arg: Curve): void
Sets the scale graph.
Parameters
arg
Returns
void
scaleGraph2
Get Signature
get scaleGraph2(): Curve
Gets the second scale graph.
Returns
Set Signature
set scaleGraph2(arg: Curve): void
Sets the second scale graph. If not null, particles pick random values between scaleGraph
and scaleGraph2
.
Parameters
arg
Returns
void
screenSpace
Get Signature
get screenSpace(): boolean
Gets whether particles are rendered in 2D screen space.
Returns
boolean
Set Signature
set screenSpace(arg: boolean): void
Sets whether particles are rendered in 2D screen space. This needs to be set when particle system is part of hierarchy with ScreenComponent as its ancestor, and allows particle system to integrate with the rendering of ElementComponents. Note that an entity with ParticleSystem component cannot be parented directly to ScreenComponent, but has to be a child of a ElementComponent, for example LayoutGroupComponent.
Parameters
arg
boolean
Returns
void
sort
Get Signature
get sort(): number
Gets the particle sorting mode.
Returns
number
Set Signature
set sort(arg: number): void
Sets the particle sorting mode. Forces CPU simulation, so be careful.
- PARTICLESORT_NONE: No sorting, particles are drawn in arbitrary order. Can be simulated on GPU.
- PARTICLESORT_DISTANCE: Sorting based on distance to the camera. CPU only.
- PARTICLESORT_NEWER_FIRST: Newer particles are drawn first. CPU only.
- PARTICLESORT_OLDER_FIRST: Older particles are drawn first. CPU only.
Parameters
arg
number
Returns
void
startAngle
Get Signature
get startAngle(): number
Gets the minimal initial Euler angle of a particle.
Returns
number
Set Signature
set startAngle(arg: number): void
Sets the minimal initial Euler angle of a particle.
Parameters
arg
number
Returns
void
startAngle2
Get Signature
get startAngle2(): number
Gets the maximal initial Euler angle of a particle.
Returns
number
Set Signature
set startAngle2(arg: number): void
Sets the maximal initial Euler angle of a particle.
Parameters
arg
number
Returns
void
stretch
Get Signature
get stretch(): number
Gets how much particles are stretched in their direction of motion.
Returns
number
Set Signature
set stretch(arg: number): void
Sets how much particles are stretched in their direction of motion. This is a value in world units that controls the amount by which particles are stretched based on their velocity. Particles are stretched from their center towards their previous position.
Parameters
arg
number
Returns
void
velocityGraph
Get Signature
get velocityGraph(): CurveSet
Gets the world space velocity graph.
Returns
Set Signature
set velocityGraph(arg: CurveSet): void
Sets the world space velocity graph.
Parameters
arg
Returns
void
velocityGraph2
Get Signature
get velocityGraph2(): CurveSet
Gets the second world space velocity graph.
Returns
Set Signature
set velocityGraph2(arg: CurveSet): void
Sets the second world space velocity graph. If not null, particles pick random values between velocityGraph and velocityGraph2.
Parameters
arg
Returns
void
wrap
Get Signature
get wrap(): boolean
Gets whether particles wrap based on the set wrap bounds.
Returns
boolean
Set Signature
set wrap(arg: boolean): void
Sets whether particles wrap based on the set wrap bounds.
Parameters
arg
boolean
Returns
void
wrapBounds
Get Signature
get wrapBounds(): Vec3
Gets the wrap bounds of the particle system.
Returns
Set Signature
set wrapBounds(arg: Vec3): void
Sets the wrap bounds of the particle system. This is half extents of a world space box volume centered on the owner entity's position. If a particle crosses the boundary of one side of the volume, it teleports to the opposite side.
Parameters
arg
Returns
void
Methods
fire()
fire(
name: string,
arg1?: any,
arg2?: any,
arg3?: any,
arg4?: any,
arg5?: any,
arg6?: any,
arg7?: any,
arg8?: any): EventHandler
Fire an event, all additional arguments are passed on to the event listener.
Parameters
name
string
Name of event to fire.
arg1?
any
First argument that is passed to the event handler.
arg2?
any
Second argument that is passed to the event handler.
arg3?
any
Third argument that is passed to the event handler.
arg4?
any
Fourth argument that is passed to the event handler.
arg5?
any
Fifth argument that is passed to the event handler.
arg6?
any
Sixth argument that is passed to the event handler.
arg7?
any
Seventh argument that is passed to the event handler.
arg8?
any
Eighth argument that is passed to the event handler.
Returns
Self for chaining.
Example
obj.fire('test', 'This is the message')
Inherited from
Component.fire
hasEvent()
hasEvent(name: string): boolean
Test if there are any handlers bound to an event name.
Parameters
name
string
The name of the event to test.
Returns
boolean
True if the object has handlers bound to the specified event name.
Example
obj.on('test', () => {}) // bind an event to 'test'
obj.hasEvent('test') // returns true
obj.hasEvent('hello') // returns false
Inherited from
Component.hasEvent
isPlaying()
isPlaying(): boolean
Checks if simulation is in progress.
Returns
boolean
True if the particle system is currently playing and false otherwise.
off()
off(
name?: string,
callback?: HandleEventCallback,
scope?: any): EventHandler
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Parameters
name?
string
Name of the event to unbind.
callback?
HandleEventCallback
Function to be unbound.
scope?
any
Scope that was used as the this when the event is fired.
Returns
Self for chaining.
Example
const handler = () => {}
obj.on('test', handler)
obj.off() // Removes all events
obj.off('test') // Removes all events called 'test'
obj.off('test', handler) // Removes all handler functions, called 'test'
obj.off('test', handler, this) // Removes all handler functions, called 'test' with scope this
Inherited from
Component.off
on()
on(
name: string,
callback: HandleEventCallback,
scope?: any): EventHandle
Attach an event handler to an event.
Parameters
name
string
Name of the event to bind the callback to.
callback
HandleEventCallback
Function that is called when event is fired. Note the callback is limited to 8 arguments.
scope?
any
= ...
Object to use as 'this' when the event is fired, defaults to current this.
Returns
Can be used for removing event in the future.
Examples
obj.on('test', (a, b) => {
console.log(a + b)
})
obj.fire('test', 1, 2) // prints 3 to the console
const evt = obj.on('test', (a, b) => {
console.log(a + b)
})
// some time later
evt.off()
Inherited from
Component.on
once()
once(
name: string,
callback: HandleEventCallback,
scope?: any): EventHandle
Attach an event handler to an event. This handler will be removed after being fired once.
Parameters
name
string
Name of the event to bind the callback to.
callback
HandleEventCallback
Function that is called when event is fired. Note the callback is limited to 8 arguments.
scope?
any
= ...
Object to use as 'this' when the event is fired, defaults to current this.
Returns
- can be used for removing event in the future.
Example
obj.once('test', (a, b) => {
console.log(a + b)
})
obj.fire('test', 1, 2) // prints 3 to the console
obj.fire('test', 1, 2) // not going to get handled
Inherited from
Component.once
pause()
pause(): void
Freezes the simulation.
Returns
void
play()
play(): void
Enables/unfreezes the simulation.
Returns
void
reset()
reset(): void
Resets particle state, doesn't affect playing.
Returns
void
stop()
stop(): void
Disables the emission of new particles, lets existing to finish their simulation.
Returns
void
unpause()
unpause(): void
Unfreezes the simulation.
Returns
void