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

Implements

Index

Constructors

constructor

  • new ParticleEmitter(x?: number, y?: number, width?: number, height?: number): ParticleEmitter
  • Parameters

    • Optional x: number

      The x position of the emitter

    • Optional y: number

      The y position of the emitter

    • Optional width: number

      The width of the emitter

    • Optional height: number

      The height of the emitter

    Returns ParticleEmitter

Properties

Private _particlesToEmit

_particlesToEmit: number = 0

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.

anchor

anchor: Vector

The anchor to apply all actor related transformations like rotation, translation, and rotation. 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

body

body: Body = new Body(this)

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.

children

children: Actor[] = []

The children of this actor

collisionGroups

collisionGroups: string[] = []

collisionType

collisionType: CollisionType = CollisionType.PreventCollision

Gets or sets the current collision type of this actor. By default it is (CollisionType.PreventCollision).

color

color: Color

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

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

currentDrawing

currentDrawing: IDrawable = 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 = Actor.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

randomRotation

randomRotation: boolean = false

Indicates whether particles should start with a random rotation

scale

scale: Vector = new ex.Vector(1, 1)

The scale vector of the actor

scene

scene: Scene = null

The scene that the actor is in

startSize

startSize: number = null

sx

sx: number = 0

The x scalar velocity of the actor in scale/second

sy

sy: number = 0

The y scalar velocity of the actor in scale/second

traits

traits: IActorTrait[] = []

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

collisionArea

  • Gets the collision area shape to use for collision possible options are [CircleArea|circles], [PolygonArea|polygons], and [EdgeArea|edges].

    Returns ICollisionArea

  • Gets the collision area shape to use for collision possible options are [CircleArea|circles], [PolygonArea|polygons], and [EdgeArea|edges].

    Parameters

    Returns void

friction

  • get friction(): number
  • set friction(theFriction: number): void
  • Gets the coefficient of friction on this actor, this can be thought of as how sticky or slippery an object is.

    Returns number

  • Sets the coefficient of friction of this actor, this can ve thought of as how stick or slippery an object is.

    Parameters

    • theFriction: number

    Returns void

mass

  • get mass(): number
  • set mass(theMass: number): void
  • Get the current mass of the actor, mass can be thought of as the resistance to acceleration.

    Returns number

  • Sets the mass of the actor, mass can be thought of as the resistance to acceleration.

    Parameters

    • theMass: number

    Returns void

moi

  • get moi(): number
  • set moi(theMoi: number): void
  • Gets the current moment of inertia, moi can be thought of as the resistance to rotation.

    Returns number

  • Sets the current moment of inertia, moi can be thought of as the resistance to rotation.

    Parameters

    • theMoi: number

    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

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

  • Gets the position vector of the actor in pixels

    Returns Vector

  • Sets the position vector of the actor in pixels

    Parameters

    Returns void

restitution

  • get restitution(): number
  • set restitution(theRestitution: number): void
  • Gets the coefficient of restitution of this actor, represents the amount of energy preserved after collision. Think of this as bounciness.

    Returns number

  • Sets the coefficient of restitution of this actor, represents the amount of energy preserved after collision. Think of this as bounciness.

    Parameters

    • theRestitution: number

    Returns void

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

torque

  • get torque(): number
  • set torque(theTorque: number): void
  • Gets the current torque applied to the actor. Torque can be thought of as rotational force

    Returns number

  • Sets the current torque applied to the actor. Torque can be thought of as rotational force

    Parameters

    • theTorque: number

    Returns void

vel

  • Gets the velocity vector of the actor in pixels/sec

    Returns Vector

  • Sets the velocity vector of the actor in pixels/sec

    Parameters

    Returns void

x

  • get x(): number
  • set x(theX: number): void
  • Gets the x position of the actor relative to it's parent (if any)

    Returns number

  • Sets the x position of the actor relative to it's parent (if any)

    Parameters

    • theX: number

    Returns void

y

  • get y(): number
  • set y(theY: number): void
  • Gets the y position of the actor relative to it's parent (if any)

    Returns number

  • Sets the y position of the actor relative to it's parent (if any)

    Parameters

    • theY: number

    Returns void

z

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

  • Parameters

    • newZ: number

    Returns void

Methods

Private _createParticle

  • Returns Particle

Protected _reapplyEffects

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

addCollisionGroup

  • addCollisionGroup(name: string): void
  • Adds an actor to a collision group. Actors with no named collision groups are considered to be in every collision group.

    Once in a collision group(s) actors will only collide with other actors in that group.

    Parameters

    • name: string

      The name of the collision group

    Returns void

addDrawing

  • addDrawing(texture: Texture): any
  • addDrawing(sprite: Sprite): any
  • addDrawing(key: any, drawing: IDrawable): any
  • Adds a whole texture as the "default" drawing. Set a drawing using setDrawing.

    Parameters

    Returns any

  • Adds a whole sprite as the "default" drawing. Set a drawing using setDrawing.

    Parameters

    Returns any

  • Adds a drawing to the list of available drawings for an actor. Set a drawing using setDrawing.

    Parameters

    Returns any

clearParticles

  • clearParticles(): void
  • Returns void

collides

  • Test whether the actor has collided with another actor, returns the intersection vector on collision. Returns null when there is no collision;

    Parameters

    • actor: Actor

      The other actor to test

    Returns Vector

collidesWithSide

  • Test whether the actor has collided with another actor, returns the side of the current actor that collided.

    Parameters

    • actor: Actor

      The other actor to test

    Returns Side

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

    • ctx: CanvasRenderingContext2D

    Returns void

draw

  • draw(ctx: CanvasRenderingContext2D, delta: number): void
  • Parameters

    • ctx: CanvasRenderingContext2D
    • delta: number

    Returns void

emit

  • emit(eventName: string, eventObject?: GameEvent): void
  • Emits a new event

    Parameters

    • eventName: string

      Name of the event to emit

    • Optional eventObject: GameEvent

      Data associated with this event

    Returns void

emitParticles

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

    Parameters

    • particleCount: number

      Number of particles to emit right now

    Returns void

getBottom

  • getBottom(): number
  • Gets the bottom edge of the actor

    Returns number

getBounds

getCenter

  • Get the center point of an actor

    Returns Vector

getCollisionHandlers

  • getCollisionHandlers(): object

getGlobalScale

getHeight

  • getHeight(): number
  • Gets the calculated height of an actor, factoring in scale

    Returns number

getLeft

  • getLeft(): number
  • Gets the left edge of the actor

    Returns number

getRelativeBounds

getRight

  • getRight(): number
  • Gets the right edge of the actor

    Returns number

getSideFromIntersect

  • Returns the side of the collision based on the intersection

    Parameters

    • intersect: Vector

      The displacement vector returned by a collision

    Returns Side

getTop

  • getTop(): number
  • Gets the top edge of the actor

    Returns number

getWidth

  • getWidth(): number
  • Gets the calculated width of an actor, factoring in scale

    Returns number

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

integrate

  • integrate(delta: number): void
  • Perform euler integration at the specified time step

    Parameters

    • delta: number

    Returns void

isKilled

  • isKilled(): boolean
  • Indicates wether the actor has been killed.

    Returns 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: string, handler?: function): void
  • Alias for removeEventListener. If only the eventName is specified it will remove all handlers registered for that specific event. If the eventName and the handler instance are specified only that handler will be removed.

    Parameters

    • eventName: string

      Name of the event to listen for

    • Optional handler: function

      Event handler for the thrown event

    Returns void

on

  • on(eventName: kill, handler: function): any
  • on(eventName: initialize, handler: function): any
  • on(eventName: preupdate, handler: function): any
  • on(eventName: postupdate, handler: function): any
  • on(eventName: predraw, handler: function): any
  • on(eventName: postdraw, handler: function): any
  • on(eventName: predebugdraw, handler: function): any
  • on(eventName: postdebugdraw, handler: function): any
  • on(eventName: pointerup, handler: function): any
  • on(eventName: pointerdown, handler: function): any
  • on(eventName: pointermove, handler: function): any
  • on(eventName: pointercancel, handler: function): any
  • on(eventName: string, handler: function): any
  • Parameters

    • eventName: kill
    • handler: function

    Returns any

  • Parameters

    Returns any

  • Parameters

    Returns any

  • Parameters

    Returns any

  • Parameters

    Returns any

  • Parameters

    Returns any

  • Parameters

    Returns any

  • Parameters

    Returns any

  • Parameters

    • eventName: pointerup
    • handler: function
        • (event?: PointerEvent): void
        • Parameters

          • Optional event: PointerEvent

          Returns void

    Returns any

  • Parameters

    • eventName: pointerdown
    • handler: function
        • (event?: PointerEvent): void
        • Parameters

          • Optional event: PointerEvent

          Returns void

    Returns any

  • Parameters

    • eventName: pointermove
    • handler: function
        • (event?: PointerEvent): void
        • Parameters

          • Optional event: PointerEvent

          Returns void

    Returns any

  • Parameters

    • eventName: pointercancel
    • handler: function
        • (event?: PointerEvent): void
        • Parameters

          • Optional event: PointerEvent

          Returns void

    Returns any

  • Parameters

    • eventName: string
    • handler: function

    Returns any

onCollidesWith

  • onCollidesWith(group: string, func: function): void
  • Register a handler to fire when this actor collides with another in a specified group

    Parameters

    • group: string

      The group name to listen for

    • func: function

      The callback to fire on collision with another actor from the group. The callback is passed the other actor.

        • Parameters

          Returns void

    Returns void

onInitialize

  • onInitialize(engine: Engine): void
  • This 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.

    Parameters

    Returns void

remove

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

    Parameters

    • actor: Actor

      The child actor to remove

    Returns void

removeCollidesWith

  • removeCollidesWith(group: string): void
  • Removes all collision handlers for this group on this actor

    Parameters

    • group: string

      Group to remove all handlers for on this actor.

    Returns void

removeCollisionGroup

  • removeCollisionGroup(name: string): void
  • Removes an actor from a collision group.

    Parameters

    • name: string

      The name of the collision group

    Returns void

removeParticle

  • removeParticle(particle: Particle): void
  • Parameters

    Returns void

setDrawing

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

    Parameters

    • key: string

      The key of the drawing

    Returns any

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

setHeight

  • setHeight(height: any): void
  • Sets the height of an actor, factoring in the current scale

    Parameters

    • height: any

    Returns void

setWidth

  • setWidth(width: any): void
  • Sets the width of an actor, factoring in the current scale

    Parameters

    • width: any

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

    • engine: Engine
    • delta: number

    Returns void

within

  • within(actor: Actor, distance: number): boolean
  • Returns true if the two actors 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

Static extend

  • extend(methods: any): any
  • You may wish to extend native Excalibur functionality in vanilla Javascript. Any method on a class inheriting Class may be extended to support additional functionality. In the example below we create a new type called MyActor.

    var MyActor = Actor.extend({
    
       constructor: function() {
          this.newprop = 'something';
          Actor.apply(this, arguments);
       },
    
       update: function(engine, delta) {
          // Implement custom update
          // Call super constructor update
          Actor.prototype.update.call(this, engine, delta);
    
          console.log("Something cool!");
       }
    });
    
    var myActor = new MyActor(100, 100, 100, 100, Color.Azure);
    

    In TypeScript, you only need to use the extends syntax, you do not need to use this method of extension.

    Parameters

    • methods: any

      A JSON object contain any methods/properties you want to extend

    Returns any

Object literals

capturePointer

capturePointer: object

Configuration for CapturePointer trait

captureMoveEvents

captureMoveEvents: boolean = false