Engine API Reference
    Preparing search index...

    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.

    Hierarchy (View Summary)

    Index

    Properties

    entity: Entity

    The Entity that this Component is attached to.

    The ComponentSystem used to create this Component.

    Accessors

    • get alignToMotion(): boolean

      Gets whether particles are oriented in their direction of motion or not.

      Returns boolean

    • set alignToMotion(arg: boolean): void

      Sets whether particles are oriented in their direction of motion or not.

      Parameters

      • arg: boolean

      Returns void

    • get alphaGraph(): Curve

      Gets the alpha graph.

      Returns Curve

    • set alphaGraph(arg: Curve): void

      Sets the alpha graph.

      Parameters

      Returns void

    • get alphaGraph2(): Curve

      Gets the second alpha graph.

      Returns Curve

    • set alphaGraph2(arg: Curve): void

      Sets the second alpha graph. If not null, particles pick random values between alphaGraph and alphaGraph2.

      Parameters

      Returns void

    • get animIndex(): number

      Gets the index of the animation to play.

      Returns number

    • 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

    • get animLoop(): boolean

      Gets whether the sprite sheet animation plays once or loops continuously.

      Returns boolean

    • set animLoop(arg: boolean): void

      Sets whether the sprite sheet animation plays once or loops continuously.

      Parameters

      • arg: boolean

      Returns void

    • get animNumAnimations(): number

      Gets the number of sprite sheet animations contained within the current sprite sheet.

      Returns number

    • 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

    • get animNumFrames(): number

      Gets the number of sprite sheet frames in the current sprite sheet animation.

      Returns number

    • 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

    • get animSpeed(): number

      Gets the sprite sheet animation speed.

      Returns number

    • 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

    • get animStartFrame(): number

      Gets the sprite sheet frame that the animation should begin playing from.

      Returns number

    • 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

    • get animTilesX(): number

      Gets the number of horizontal tiles in the sprite sheet.

      Returns number

    • set animTilesX(arg: number): void

      Sets the number of horizontal tiles in the sprite sheet.

      Parameters

      • arg: number

      Returns void

    • get animTilesY(): number

      Gets the number of vertical tiles in the sprite sheet.

      Returns number

    • set animTilesY(arg: number): void

      Sets the number of vertical tiles in the sprite sheet.

      Parameters

      • arg: number

      Returns void

    • get autoPlay(): boolean

      Gets whether the particle system plays automatically on creation.

      Returns boolean

    • 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

    • get blendType(): number

      Gets how particles are blended when being written to the currently active render target.

      Returns number

    • set blendType(arg: number): void

      Sets how particles are blended when being written to the currently active render target. Can be:

      Parameters

      • arg: number

      Returns void

    • get colorGraph2(): CurveSet

      Gets the second color graph.

      Returns CurveSet

    • set colorGraph2(arg: CurveSet): void

      Sets the second color graph. If not null, particles pick random values between colorGraph and colorGraph2.

      Parameters

      Returns void

    • get colorMap(): Texture

      Gets the color map texture to apply to all particles in the system.

      Returns Texture

    • 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

      Returns void

    • get colorMapAsset(): Asset

      Gets the Asset used to set the colorMap.

      Returns Asset

    • set colorMapAsset(arg: Asset): void

      Sets the Asset used to set the colorMap.

      Parameters

      Returns void

    • get depthSoftening(): number

      Gets whether depth softening is enabled.

      Returns number

    • 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

    • get depthWrite(): boolean

      Gets whether depth writes is enabled.

      Returns boolean

    • 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

    • get drawOrder(): number

      Gets the draw order of the component.

      Returns number

    • 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

    • get emitterExtents(): Vec3

      Gets the extents of a local space bounding box within which particles are spawned at random positions.

      Returns Vec3

    • 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

      Returns void

    • get emitterExtentsInner(): Vec3

      Gets the exception of extents of a local space bounding box within which particles are not spawned.

      Returns Vec3

    • 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

      Returns void

    • get emitterRadius(): number

      Gets the radius within which particles are spawned at random positions.

      Returns number

    • 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

    • get emitterRadiusInner(): number

      Gets the inner radius within which particles are not spawned.

      Returns number

    • 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

    • get emitterShape(): number

      Gets the shape of the emitter.

      Returns number

    • 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

    • get enabled(): boolean

      Gets the enabled state of the component.

      Returns boolean

    • set enabled(arg: boolean): void

      Sets the enabled state of the component.

      Parameters

      • arg: boolean

      Returns void

    • get halfLambert(): boolean

      Gets whether Half Lambert lighting is enabled.

      Returns boolean

    • 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

    • get initialVelocity(): number

      Gets the magnitude of the initial emitter velocity.

      Returns number

    • set initialVelocity(arg: number): void

      Sets the magnitude of the initial emitter velocity. Direction is given by emitter shape.

      Parameters

      • arg: number

      Returns void

    • get intensity(): number

      Gets the color multiplier.

      Returns number

    • set intensity(arg: number): void

      Sets the color multiplier.

      Parameters

      • arg: number

      Returns void

    • get layers(): number[]

      Gets the array of layer IDs (Layer#id) to which this particle system belongs.

      Returns number[]

    • 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

    • get lifetime(): number

      Gets the length of time in seconds between a particle's birth and its death.

      Returns number

    • 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

    • get lighting(): boolean

      Gets whether particles will be lit by ambient and directional lights.

      Returns boolean

    • set lighting(arg: boolean): void

      Sets whether particles will be lit by ambient and directional lights.

      Parameters

      • arg: boolean

      Returns void

    • get localSpace(): boolean

      Gets whether particles move with respect to the emitter's transform rather then world space.

      Returns boolean

    • 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

    • get localVelocityGraph(): CurveSet

      Gets the local space velocity graph.

      Returns CurveSet

    • set localVelocityGraph(arg: CurveSet): void

      Sets the local space velocity graph.

      Parameters

      Returns void

    • get localVelocityGraph2(): CurveSet

      Gets the second velocity graph.

      Returns CurveSet

    • set localVelocityGraph2(arg: CurveSet): void

      Sets the second velocity graph. If not null, particles pick random values between localVelocityGraph and localVelocityGraph2.

      Parameters

      Returns void

    • get loop(): boolean

      Gets whether the particle system loops.

      Returns boolean

    • set loop(arg: boolean): void

      Sets whether the particle system loops.

      Parameters

      • arg: boolean

      Returns void

    • get mesh(): Mesh

      Gets the polygonal mesh to be used as a particle.

      Returns Mesh

    • 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

      Returns void

    • get meshAsset(): Asset

      Gets the Asset used to set the mesh.

      Returns Asset

    • set meshAsset(arg: Asset): void

      Sets the Asset used to set the mesh.

      Parameters

      Returns void

    • get noFog(): boolean

      Gets whether fogging is ignored.

      Returns boolean

    • set noFog(arg: boolean): void

      Sets whether fogging is ignored.

      Parameters

      • arg: boolean

      Returns void

    • get normalMap(): Texture

      Gets the normal map texture to apply to all particles in the system.

      Returns Texture

    • 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

      Returns void

    • get normalMapAsset(): Asset

      Gets the Asset used to set the normalMap.

      Returns Asset

    • set normalMapAsset(arg: Asset): void

      Sets the Asset used to set the normalMap.

      Parameters

      Returns void

    • get numParticles(): number

      Gets the maximum number of simulated particles.

      Returns number

    • set numParticles(arg: number): void

      Sets the maximum number of simulated particles.

      Parameters

      • arg: number

      Returns void

    • get orientation(): number

      Gets the particle orientation mode.

      Returns number

    • set orientation(arg: number): void

      Sets the particle orientation mode. Can be:

      Parameters

      • arg: number

      Returns void

    • get particleNormal(): Vec3

      Gets the particle normal.

      Returns Vec3

    • 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

      Returns void

    • get preWarm(): boolean

      Gets whether the particle system will be initialized as though it has already completed a full cycle.

      Returns boolean

    • 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

    • get radialSpeedGraph(): Curve

      Gets the radial speed graph.

      Returns Curve

    • set radialSpeedGraph(arg: Curve): void

      Sets the radial speed graph. Velocity vector points from emitter origin to particle position.

      Parameters

      Returns void

    • get radialSpeedGraph2(): Curve

      Gets the second radial speed graph.

      Returns Curve

    • 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

      Returns void

    • 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 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

    • get rate(): number

      Gets the minimal interval in seconds between particle births.

      Returns number

    • set rate(arg: number): void

      Sets the minimal interval in seconds between particle births.

      Parameters

      • arg: number

      Returns void

    • get rate2(): number

      Gets the maximal interval in seconds between particle births.

      Returns number

    • set rate2(arg: number): void

      Sets the maximal interval in seconds between particle births.

      Parameters

      • arg: number

      Returns void

    • get renderAsset(): Asset

      Gets the Render Asset used to set the mesh.

      Returns Asset

    • set renderAsset(arg: Asset): void

      Sets the Render Asset used to set the mesh.

      Parameters

      Returns void

    • get rotationSpeedGraph(): Curve

      Gets the rotation speed graph.

      Returns Curve

    • set rotationSpeedGraph(arg: Curve): void

      Sets the rotation speed graph.

      Parameters

      Returns void

    • get rotationSpeedGraph2(): Curve

      Gets the second rotation speed graph.

      Returns Curve

    • set rotationSpeedGraph2(arg: Curve): void

      Sets the second rotation speed graph. If not null, particles pick random values between rotationSpeedGraph and rotationSpeedGraph2.

      Parameters

      Returns void

    • get scaleGraph(): Curve

      Gets the scale graph.

      Returns Curve

    • set scaleGraph(arg: Curve): void

      Sets the scale graph.

      Parameters

      Returns void

    • get scaleGraph2(): Curve

      Gets the second scale graph.

      Returns Curve

    • set scaleGraph2(arg: Curve): void

      Sets the second scale graph. If not null, particles pick random values between scaleGraph and scaleGraph2.

      Parameters

      Returns void

    • get screenSpace(): boolean

      Gets whether particles are rendered in 2D screen space.

      Returns boolean

    • 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

    • get sort(): number

      Gets the particle sorting mode.

      Returns number

    • set sort(arg: number): void

      Sets the particle sorting mode. Forces CPU simulation, so be careful.

      Parameters

      • arg: number

      Returns void

    • get startAngle(): number

      Gets the minimal initial Euler angle of a particle.

      Returns number

    • set startAngle(arg: number): void

      Sets the minimal initial Euler angle of a particle.

      Parameters

      • arg: number

      Returns void

    • get startAngle2(): number

      Gets the maximal initial Euler angle of a particle.

      Returns number

    • set startAngle2(arg: number): void

      Sets the maximal initial Euler angle of a particle.

      Parameters

      • arg: number

      Returns void

    • get stretch(): number

      Gets how much particles are stretched in their direction of motion.

      Returns number

    • 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

    • get velocityGraph(): CurveSet

      Gets the world space velocity graph.

      Returns CurveSet

    • set velocityGraph(arg: CurveSet): void

      Sets the world space velocity graph.

      Parameters

      Returns void

    • get velocityGraph2(): CurveSet

      Gets the second world space velocity graph.

      Returns CurveSet

    • set velocityGraph2(arg: CurveSet): void

      Sets the second world space velocity graph. If not null, particles pick random values between velocityGraph and velocityGraph2.

      Parameters

      Returns void

    • get wrap(): boolean

      Gets whether particles wrap based on the set wrap bounds.

      Returns boolean

    • set wrap(arg: boolean): void

      Sets whether particles wrap based on the set wrap bounds.

      Parameters

      • arg: boolean

      Returns void

    • get wrapBounds(): Vec3

      Gets the wrap bounds of the particle system.

      Returns Vec3

    • 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

      Returns void

    Methods

    • Fire an event, all additional arguments are passed on to the event listener.

      Parameters

      • name: string

        Name of event to fire.

      • Optionalarg1: any

        First argument that is passed to the event handler.

      • Optionalarg2: any

        Second argument that is passed to the event handler.

      • Optionalarg3: any

        Third argument that is passed to the event handler.

      • Optionalarg4: any

        Fourth argument that is passed to the event handler.

      • Optionalarg5: any

        Fifth argument that is passed to the event handler.

      • Optionalarg6: any

        Sixth argument that is passed to the event handler.

      • Optionalarg7: any

        Seventh argument that is passed to the event handler.

      • Optionalarg8: any

        Eighth argument that is passed to the event handler.

      Returns EventHandler

      Self for chaining.

      obj.fire('test', 'This is the message');
      
    • 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.

      obj.on('test', () => {}); // bind an event to 'test'
      obj.hasEvent('test'); // returns true
      obj.hasEvent('hello'); // returns false
    • Checks if simulation is in progress.

      Returns boolean

      True if the particle system is currently playing and false otherwise.

    • 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

      • Optionalname: string

        Name of the event to unbind.

      • Optionalcallback: HandleEventCallback

        Function to be unbound.

      • Optionalscope: any

        Scope that was used as the this when the event is fired.

      Returns EventHandler

      Self for chaining.

      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
    • 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.

      • Optionalscope: any = ...

        Object to use as 'this' when the event is fired, defaults to current this.

      Returns EventHandle

      Can be used for removing event in the future.

      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();
    • 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.

      • Optionalscope: any = ...

        Object to use as 'this' when the event is fired, defaults to current this.

      Returns EventHandle

      • can be used for removing event in the future.
      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
    • Freezes the simulation.

      Returns void

    • Enables/unfreezes the simulation.

      Returns void

    • Resets particle state, doesn't affect playing.

      Returns void

    • Disables the emission of new particles, lets existing to finish their simulation.

      Returns void

    • Unfreezes the simulation.

      Returns void