Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ParticleEmitter

Using a particle emitter is a great way to create interesting effects in your game, like smoke, fire, water, explosions, etc. ParticleEmitter extend Actor allowing you to use all of the features that come with.

The easiest way to create a ParticleEmitter is to use the Particle Tester to generate code for emitters.

Example: Adding an emitter

var actor = new ex.Actor(...);
var emitter = new ex.ParticleEmitter(...);
emitter.emitterType = ex.EmitterType.Circle; // Shape of emitter nozzle
emitter.radius = 5;
emitter.minVel = 100;
emitter.maxVel = 200;
emitter.minAngle = 0;
emitter.maxAngle = Math.PI * 2;
emitter.emitRate = 300; // 300 particles/second
emitter.opacity = 0.5;
emitter.fadeFlag = true; // fade particles overtime
emitter.particleLife = 1000; // in milliseconds = 1 sec
emitter.maxSize = 10; // in pixels
emitter.minSize = 1;
emitter.particleColor = ex.Color.Rose;
// set emitter settings
emitter.isEmitting = true;  // should the emitter be emitting
// add the emitter as a child actor, it will draw on top of the parent actor
// and move with the parent
actor.add(emitter);
// or, alternatively, add it to the current scene
engine.add(emitter);

Hierarchy

  • ParticleEmitterImpl
    • ParticleEmitter

Implements

Index

Constructors

constructor

Properties

acceleration

acceleration: Vector = new Vector(0, 0)

Gets or sets the acceleration vector for all particles

actionQueue

actionQueue: ActionQueue

Direct access to the actor's ActionQueue. Useful if you are building custom actions.

actions

actions: ActionContext

Action context of the actor. Useful for scripting actor behavior.

active

active: boolean = true

Whether this entity is active, if set to false it will be reclaimed

anchor

anchor: Vector

The anchor to apply all actor related transformations like rotation, translation, and scaling. By default the anchor is in the center of the actor. By default it is set to the center of the actor (.5, .5)

An anchor of (.5, .5) will ensure that drawings are centered.

Use anchor.setTo to set the anchor to a different point using values between 0 and 1. For example, anchoring to the top-left would be Actor.anchor.setTo(0, 0) and top-right would be Actor.anchor.setTo(0, 1).

beginColor

beginColor: Color = Color.White

Gets or sets the beginning color of all particles

changes

changes: Observable<AddedComponent | RemovedComponent> = new Observable<AddedComponent | RemovedComponent>()

children

children: Actor[] = []

The children of this actor

components

components: ComponentMapper<KnownComponents> = new Proxy<ComponentMapper<KnownComponents>>({} as any, this._handleChanges)

currentDrawing

currentDrawing: Drawable = null

Access to the current drawing for the actor, this can be an Animation, Sprite, or Polygon. Set drawings with setDrawing.

deadParticles

deadParticles: Collection<Particle> = null

Gets or sets the backing deadParticle collection

emitRate

emitRate: number = 1

Gets or sets the emission rate for particles (particles/sec)

emitterType

emitterType: EmitterType = EmitterType.Rectangle

Gets or sets the emitter type for the particle emitter

enableCapturePointer

enableCapturePointer: boolean = false

Whether or not to enable the CapturePointer trait that propagates pointer events to this actor

endColor

endColor: Color = Color.White

Gets or sets the ending color of all particles

endSize

endSize: number = null

eventDispatcher

eventDispatcher: EventDispatcher

Direct access to the game object event dispatcher.

fadeFlag

fadeFlag: boolean = false

Gets or sets the fade flag which causes particles to gradually fade out over the course of their life.

focus

focus: Vector = null

Gets or sets the optional focus where all particles should accelerate towards

focusAccel

focusAccel: number = 1

Gets or sets the acceleration for focusing particles if a focus has been specified

frames

frames: object

Type declaration

id

id: number = ActorImpl.maxId++

The unique identifier for the actor

isEmitting

isEmitting: boolean = true

Gets or sets the isEmitting flag

isOffScreen

isOffScreen: boolean = false

Indicates whether the actor is physically in the viewport

logger

logger: Logger = Logger.getInstance()

Convenience reference to the global logger

maxAngle

maxAngle: number = 0

Gets or sets the maximum angle in radians

maxSize

maxSize: number = 5

Gets or sets the maximum size of all particles

maxVel

maxVel: number = 0

Gets or sets the maximum particle velocity

minAngle

minAngle: number = 0

Gets or sets the minimum angle in radians

minSize

minSize: number = 5

Gets or sets the minimum size of all particles

minVel

minVel: number = 0

Gets or sets the minimum particle velocity

numParticles

numParticles: number = 0

opacity

opacity: number = 1

Gets or sets the opacity of each particle from 0 to 1.0

parent

parent: Actor = null

The parent of this actor

particleLife

particleLife: number = 2000

Gets or sets the life of each particle in milliseconds

particleRotationalVelocity

particleRotationalVelocity: number = 0

Gets or sets the particle rotational speed velocity

particleSprite

particleSprite: Sprite = null

Gets or sets the sprite that a particle should use

warning

Performance intensive

particles

particles: Collection<Particle> = null

Gets or sets the backing particle collection

previousOpacity

previousOpacity: number = 1

radius

radius: number = 0

Gets or sets the emitter radius, only takes effect when the emitterType is EmitterType.Circle

random

random: Random

Random number generator

randomRotation

randomRotation: boolean = false

Indicates whether particles should start with a random rotation

scene

scene: Scene = null

The scene that the actor is in

startSize

startSize: number = null

traits

traits: Trait[] = []

Modify the current actor update pipeline.

visible

visible: boolean = true

The visibility of an actor

Static maxId

maxId: number = 0

Indicates the next id to be set

Accessors

acc

  • Gets the acceleration vector of the actor in pixels/second/second. An acceleration pointing down such as (0, 100) may be useful to simulate a gravitational effect.

    Returns Vector

  • Sets the acceleration vector of teh actor in pixels/second/second

    Parameters

    Returns void

body

  • get body(): Body
  • set body(body: Body): void
  • The physics body the is associated with this actor. The body is the container for all physical properties, like position, velocity, acceleration, mass, inertia, etc.

    Returns Body

  • The physics body the is associated with this actor. The body is the container for all physical properties, like position, velocity, acceleration, mass, inertia, etc.

    Parameters

    Returns void

center

color

  • Sets the color of the actor. A rectangle of this color will be drawn if no Drawable is specified as the actors drawing.

    The default is null which prevents a rectangle from being drawn.

    Returns Color

  • Sets the color of the actor. A rectangle of this color will be drawn if no Drawable is specified as the actors drawing.

    The default is null which prevents a rectangle from being drawn.

    Parameters

    Returns void

draggable

  • get draggable(): boolean
  • set draggable(isDraggable: boolean): void

height

  • get height(): number
  • set height(height: number): void

isInitialized

  • get isInitialized(): boolean

oldAcc

  • Gets the acceleration of the actor from the last frame. This does not include the global acc Physics.acc.

    Returns Vector

  • Sets the acceleration of the actor from the last frame. This does not include the global acc Physics.acc.

    Parameters

    Returns void

oldPos

  • Gets the position vector of the actor from the last frame

    Returns Vector

  • Sets the position vector of the actor in the last frame

    Parameters

    Returns void

oldScale

  • Gets the old scale of the actor last frame

    obsolete

    ex.Actor.scale will be removed in v0.25.0, set width and height directly in constructor

    Returns Vector

  • Sets the the old scale of the actor last frame

    obsolete

    ex.Actor.scale will be removed in v0.25.0, set width and height directly in constructor

    Parameters

    Returns void

oldVel

  • Gets the velocity vector of the actor from the last frame

    Returns Vector

  • Sets the velocity vector of the actor from the last frame

    Parameters

    Returns void

pos

rotation

  • get rotation(): number
  • set rotation(theAngle: number): void
  • Gets the rotation of the actor in radians. 1 radian = 180/PI Degrees.

    Returns number

  • Sets the rotation of the actor in radians. 1 radian = 180/PI Degrees.

    Parameters

    • theAngle: number

    Returns void

rx

  • get rx(): number
  • set rx(angularVelocity: number): void
  • Gets the rotational velocity of the actor in radians/second

    Returns number

  • Sets the rotational velocity of the actor in radians/sec

    Parameters

    • angularVelocity: number

    Returns void

scale

  • Gets the scale vector of the actor

    obsolete

    ex.Actor.scale will be removed in v0.25.0, set width and height directly in constructor

    Returns Vector

  • Sets the scale vector of the actor for

    obsolete

    ex.Actor.scale will be removed in v0.25.0, set width and height directly in constructor

    Parameters

    Returns void

sx

  • get sx(): number
  • set sx(scalePerSecondX: number): void
  • Gets the x scalar velocity of the actor in scale/second

    obsolete

    ex.Actor.sx will be removed in v0.25.0, set width and height directly in constructor

    Returns number

  • Sets the x scalar velocity of the actor in scale/second

    obsolete

    ex.Actor.sx will be removed in v0.25.0, set width and height directly in constructor

    Parameters

    • scalePerSecondX: number

    Returns void

sy

  • get sy(): number
  • set sy(scalePerSecondY: number): void
  • Gets the y scalar velocity of the actor in scale/second

    obsolete

    ex.Actor.sy will be removed in v0.25.0, set width and height directly in constructor

    Returns number

  • Sets the y scale velocity of the actor in scale/second

    obsolete

    ex.Actor.sy will be removed in v0.25.0, set width and height directly in constructor

    Parameters

    • scalePerSecondY: number

    Returns void

types

  • get types(): string[]

vel

width

  • get width(): number
  • set width(width: number): void

z

  • get z(): number
  • set z(newZ: number): void

Methods

_initialize

  • _initialize(engine: Engine): void
  • Initializes this actor and all it's child actors, meant to be called by the Scene before first update not by users of Excalibur.

    It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    internal

    Parameters

    Returns void

_postdraw

  • _postdraw(ctx: CanvasRenderingContext2D, delta: number): void
  • It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _postdraw handler for onPostDraw lifecycle event

    internal

    Parameters

    • ctx: CanvasRenderingContext2D
    • delta: number

    Returns void

_postkill

  • _postkill(_scene: Scene): void
  • It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _prekill handler for onPostKill lifecycle event

    internal

    Parameters

    Returns void

_postupdate

  • _postupdate(engine: Engine, delta: number): void
  • It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _preupdate handler for onPostUpdate lifecycle event

    internal

    Parameters

    • engine: Engine
    • delta: number

    Returns void

_predraw

  • _predraw(ctx: CanvasRenderingContext2D, delta: number): void
  • It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _predraw handler for onPreDraw lifecycle event

    internal

    Parameters

    • ctx: CanvasRenderingContext2D
    • delta: number

    Returns void

_prekill

  • _prekill(_scene: Scene): void
  • It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _prekill handler for onPreKill lifecycle event

    internal

    Parameters

    Returns void

_preupdate

  • _preupdate(engine: Engine, delta: number): void
  • It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _preupdate handler for onPreUpdate lifecycle event

    internal

    Parameters

    • engine: Engine
    • delta: number

    Returns void

add

  • add(actor: Actor): void
  • Adds a child actor to this actor. All movement of the child actor will be relative to the parent actor. Meaning if the parent moves the child will move with it.

    Parameters

    • actor: Actor

      The child actor to add

    Returns void

addComponent

  • addComponent<T>(componentOrEntity: T | Entity<T>, force?: boolean): Entity<never | T>

addDrawing

  • addDrawing(texture: Texture): void
  • addDrawing(sprite: Sprite): void
  • addDrawing(key: any, drawing: Drawable): void

clearParticles

  • clearParticles(): void

clone

contains

  • contains(x: number, y: number, recurse?: boolean): boolean
  • Tests whether the x/y specified are contained in the actor

    Parameters

    • x: number

      X coordinate to test (in world coordinates)

    • y: number

      Y coordinate to test (in world coordinates)

    • Default value recurse: boolean = false

      checks whether the x/y are contained in any child actors (if they exist).

    Returns boolean

debugDraw

  • debugDraw(ctx: CanvasRenderingContext2D): void

draw

  • draw(ctx: CanvasRenderingContext2D): void

emit

  • emit(eventName: string, eventObject: GameEvent<any>): void

emitParticles

  • emitParticles(particleCount: number): void
  • Causes the emitter to emit particles

    Parameters

    • particleCount: number

      Number of particles to emit right now

    Returns void

getAncestors

  • getAncestors(): Actor[]

getGlobalScale

getWorldPos

  • Gets an actor's world position taking into account parent relationships, scaling, rotation, and translation

    Returns Vector

    Position in world coordinates

getWorldRotation

  • getWorldRotation(): number
  • Gets this actor's rotation taking into account any parent relationships

    Returns number

    Rotation angle in radians

getZIndex

  • getZIndex(): number
  • Gets the z-index of an actor. The z-index determines the relative order an actor is drawn in. Actors with a higher z-index are drawn on top of actors with a lower z-index

    Returns number

has

  • has(type: string): boolean

isKilled

  • isKilled(): boolean

kill

  • kill(): void
  • If the current actor is a member of the scene, this will remove it from the scene graph. It will no longer be drawn or updated.

    Returns void

off

  • off(eventName: Events.exittrigger, handler?: function): void
  • off(eventName: Events.entertrigger, handler?: function): void
  • off(eventName: Events.collisionstart, handler?: function): void
  • off(eventName: Events.collisionend, handler?: function): void
  • off(eventName: Events.precollision, handler?: function): void
  • off(eventName: Events.postcollision, handler: function): void
  • off(eventName: Events.pointerup, handler?: function): void
  • off(eventName: Events.pointerdown, handler?: function): void
  • off(eventName: Events.pointerenter, handler?: function): void
  • off(eventName: Events.pointerleave, handler?: function): void
  • off(eventName: Events.pointermove, handler?: function): void
  • off(eventName: Events.pointercancel, handler?: function): void
  • off(eventName: Events.pointerwheel, handler?: function): void
  • off(eventName: Events.pointerdragstart, handler?: function): void
  • off(eventName: Events.pointerdragend, handler?: function): void
  • off(eventName: Events.pointerdragenter, handler?: function): void
  • off(eventName: Events.pointerdragleave, handler?: function): void
  • off(eventName: Events.pointerdragmove, handler?: function): void
  • off(eventName: Events.prekill, handler?: function): void
  • off(eventName: Events.postkill, handler?: function): void
  • off(eventName: Events.initialize, handler?: function): void
  • off(eventName: Events.postupdate, handler?: function): void
  • off(eventName: Events.preupdate, handler?: function): void
  • off(eventName: Events.postdraw, handler?: function): void
  • off(eventName: Events.predraw, handler?: function): void
  • off(eventName: Events.enterviewport, handler?: function): void
  • off(eventName: Events.exitviewport, handler?: function): void
  • off(eventName: string, handler?: function): void

on

  • on(eventName: Events.exittrigger, handler: function): void
  • on(eventName: Events.entertrigger, handler: function): void
  • on(eventName: Events.collisionstart, handler: function): void
  • on(eventName: Events.collisionend, handler: function): void
  • on(eventName: Events.precollision, handler: function): void
  • on(eventName: Events.postcollision, handler: function): void
  • on(eventName: Events.kill, handler: function): void
  • on(eventName: Events.prekill, handler: function): void
  • on(eventName: Events.postkill, handler: function): void
  • on(eventName: Events.initialize, handler: function): void
  • on(eventName: Events.preupdate, handler: function): void
  • on(eventName: Events.postupdate, handler: function): void
  • on(eventName: Events.predraw, handler: function): void
  • on(eventName: Events.postdraw, handler: function): void
  • on(eventName: Events.predebugdraw, handler: function): void
  • on(eventName: Events.postdebugdraw, handler: function): void
  • on(eventName: Events.pointerup, handler: function): void
  • on(eventName: Events.pointerdown, handler: function): void
  • on(eventName: Events.pointerenter, handler: function): void
  • on(eventName: Events.pointerleave, handler: function): void
  • on(eventName: Events.pointermove, handler: function): void
  • on(eventName: Events.pointercancel, handler: function): void
  • on(eventName: Events.pointerwheel, handler: function): void
  • on(eventName: Events.pointerdragstart, handler: function): void
  • on(eventName: Events.pointerdragend, handler: function): void
  • on(eventName: Events.pointerdragenter, handler: function): void
  • on(eventName: Events.pointerdragleave, handler: function): void
  • on(eventName: Events.pointerdragmove, handler: function): void
  • on(eventName: Events.enterviewport, handler: function): void
  • on(eventName: Events.exitviewport, handler: function): void
  • on(eventName: string, handler: function): void

onInitialize

  • onInitialize(_engine: Engine): void
  • onInitialize is called before the first update of the actor. This method is meant to be overridden. This is where initialization of child actors should take place.

    Synonymous with the event handler .on('initialize', (evt) => {...})

    Parameters

    Returns void

onPostDraw

  • onPostDraw(_ctx: CanvasRenderingContext2D, _delta: number): void
  • Safe to override onPostDraw lifecycle event handler. Synonymous with .on('postdraw', (evt) =>{...})

    onPostDraw is called directly after an actor is drawn, and before local transforms are removed.

    Parameters

    • _ctx: CanvasRenderingContext2D
    • _delta: number

    Returns void

onPostKill

  • onPostKill(_scene: Scene): void
  • Safe to override onPostKill lifecycle event handler. Synonymous with .on('postkill', (evt) => {...})

    onPostKill is called directly after an actor is killed and remove from its current Scene.

    Parameters

    Returns void

onPostUpdate

  • onPostUpdate(_engine: Engine, _delta: number): void
  • Safe to override onPostUpdate lifecycle event handler. Synonymous with .on('postupdate', (evt) =>{...})

    onPostUpdate is called directly after an actor is updated.

    Parameters

    • _engine: Engine
    • _delta: number

    Returns void

onPreDraw

  • onPreDraw(_ctx: CanvasRenderingContext2D, _delta: number): void
  • Safe to override onPreDraw lifecycle event handler. Synonymous with .on('predraw', (evt) =>{...})

    onPreDraw is called directly before an actor is drawn, but after local transforms are made.

    Parameters

    • _ctx: CanvasRenderingContext2D
    • _delta: number

    Returns void

onPreKill

  • onPreKill(_scene: Scene): void
  • Safe to override onPreKill lifecycle event handler. Synonymous with .on('prekill', (evt) =>{...})

    onPreKill is called directly before an actor is killed and removed from its current Scene.

    Parameters

    Returns void

onPreUpdate

  • onPreUpdate(_engine: Engine, _delta: number): void
  • Safe to override onPreUpdate lifecycle event handler. Synonymous with .on('preupdate', (evt) =>{...})

    onPreUpdate is called directly before an actor is updated.

    Parameters

    • _engine: Engine
    • _delta: number

    Returns void

once

  • once(eventName: Events.exittrigger, handler: function): void
  • once(eventName: Events.entertrigger, handler: function): void
  • once(eventName: Events.collisionstart, handler: function): void
  • once(eventName: Events.collisionend, handler: function): void
  • once(eventName: Events.precollision, handler: function): void
  • once(eventName: Events.postcollision, handler: function): void
  • once(eventName: Events.kill, handler: function): void
  • once(eventName: Events.postkill, handler: function): void
  • once(eventName: Events.prekill, handler: function): void
  • once(eventName: Events.initialize, handler: function): void
  • once(eventName: Events.preupdate, handler: function): void
  • once(eventName: Events.postupdate, handler: function): void
  • once(eventName: Events.predraw, handler: function): void
  • once(eventName: Events.postdraw, handler: function): void
  • once(eventName: Events.predebugdraw, handler: function): void
  • once(eventName: Events.postdebugdraw, handler: function): void
  • once(eventName: Events.pointerup, handler: function): void
  • once(eventName: Events.pointerdown, handler: function): void
  • once(eventName: Events.pointerenter, handler: function): void
  • once(eventName: Events.pointerleave, handler: function): void
  • once(eventName: Events.pointermove, handler: function): void
  • once(eventName: Events.pointercancel, handler: function): void
  • once(eventName: Events.pointerwheel, handler: function): void
  • once(eventName: Events.pointerdragstart, handler: function): void
  • once(eventName: Events.pointerdragend, handler: function): void
  • once(eventName: Events.pointerdragenter, handler: function): void
  • once(eventName: Events.pointerdragleave, handler: function): void
  • once(eventName: Events.pointerdragmove, handler: function): void
  • once(eventName: Events.enterviewport, handler: function): void
  • once(eventName: Events.exitviewport, handler: function): void
  • once(eventName: string, handler: function): void

remove

  • remove(actor: Actor): void
  • Removes a child actor from this actor.

    Parameters

    • actor: Actor

      The child actor to remove

    Returns void

removeComponent

  • removeComponent<ComponentOrType>(componentOrType: ComponentOrType, force?: boolean): Entity<ExcludeType<never, ComponentOrType>>
  • Removes a component from the entity, by default removals are deferred to the end of entity processing to avoid consistency issues

    Components can be force removed with the force flag, the removal is not deferred and happens immediately

    Type parameters

    Parameters

    • componentOrType: ComponentOrType
    • Default value force: boolean = false

    Returns Entity<ExcludeType<never, ComponentOrType>>

removeParticle

  • removeParticle(particle: Particle): void

setDrawing

  • setDrawing(key: string): void
  • setDrawing(key: number): void
  • Sets the current drawing of the actor to the drawing corresponding to the key.

    Parameters

    • key: string

      The key of the drawing

    Returns void

  • Sets the current drawing of the actor to the drawing corresponding to an enum key (e.g. Animations.Left)

    Parameters

    • key: number

      The enum key of the drawing

    Returns void

setZIndex

  • setZIndex(newIndex: number): void
  • Sets the z-index of an actor and updates it in the drawing list for the scene. The z-index determines the relative order an actor is drawn in. Actors with a higher z-index are drawn on top of actors with a lower z-index

    Parameters

    • newIndex: number

      new z-index to assign

    Returns void

unkill

  • unkill(): void
  • If the current actor is killed, it will now not be killed.

    Returns void

update

  • update(engine: Engine, delta: number): void

within

  • within(actor: Actor, distance: number): boolean
  • Returns true if the two actor.body.collider.shape's surfaces are less than or equal to the distance specified from each other

    Parameters

    • actor: Actor

      Actor to test

    • distance: number

      Distance in pixels to test

    Returns boolean

Object literals

capturePointer

capturePointer: object

Configuration for CapturePointer trait

captureDragEvents

captureDragEvents: false = false

captureMoveEvents

captureMoveEvents: false = false

Static defaults

defaults: object

Indicates the next id to be set

anchor

anchor: Vector = Vector.Half