Skip to main content

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.

Hierarchy

Index

Constructors

constructor

Properties

publicacceleration

acceleration: Vector = ...

Gets or sets the acceleration vector for all particles

publicactions

Useful for quickly scripting actor behavior, like moving to a place, patrolling back and forth, blinking, etc.

Access to the Actor's built in [[ActionsComponent]] which forwards to the [[ActionContext|Action context]] of the actor.

publicactive

active: boolean = true

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

publicbeginColor

beginColor: Color = Color.White

Gets or sets the beginning color of all particles

publicbody

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.

publicchildrenAdded$

childrenAdded$: Observable<Entity<any>> = ...

publicchildrenRemoved$

childrenRemoved$: Observable<Entity<any>> = ...

publiccollider

Access to the Actor's built in [[ColliderComponent]]

publiccomponentAdded$

componentAdded$: Observable<Component> = ...

publiccomponentRemoved$

componentRemoved$: Observable<Component> = ...

publicreadonlycomponents

components: Map<Function, Component> = ...

Current components on the entity

Do not modify

Use addComponent/removeComponent otherwise the ECS will not be notified of changes.

publicdeadParticles

deadParticles: Particle[] = []

Gets or sets the backing deadParticle collection

publicemitRate

emitRate: number = 1

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

publicemitterType

emitterType: EmitterType = EmitterType.Rectangle

Gets or sets the emitter type for the particle emitter

publicendColor

endColor: Color = Color.White

Gets or sets the ending color of all particles

publicendSize

endSize: number = null

Gets or sets the optional ending size for the particles

publicevents

events: EventEmitter<ActorEvents> = ...

Listen to or emit events for an entity

publicfadeFlag

fadeFlag: boolean = false

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

publicfocus

focus: Vector = null

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

publicfocusAccel

focusAccel: number = null

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

publicgraphics

Access to the Actor's built in [[GraphicsComponent]]

publicid

id: number = ...

The unique identifier for the entity

publicisEmitting

isEmitting: boolean = true

Gets or sets the isEmitting flag

publiclogger

logger: Logger = ...

Convenience reference to the global logger

publicmaxAngle

maxAngle: number = 0

Gets or sets the maximum angle in radians

publicmaxSize

maxSize: number = 5

Gets or sets the maximum size of all particles

publicmaxVel

maxVel: number = 0

Gets or sets the maximum particle velocity

publicminAngle

minAngle: number = 0

Gets or sets the minimum angle in radians

publicminSize

minSize: number = 5

Gets or sets the minimum size of all particles

publicminVel

minVel: number = 0

Gets or sets the minimum particle velocity

publicmotion

Access the Actor's built in [[MotionComponent]]

publicname

name: string = ...

publicnumParticles

numParticles: number = 0

publicparticleLife

particleLife: number = 2000

Gets or sets the life of each particle in milliseconds

publicparticleRotationalVelocity

particleRotationalVelocity: number = 0

Gets or sets the particle rotational speed velocity

publicparticleTransform

particleTransform: ParticleTransform = ParticleTransform.Global

Gets or sets the emitted particle transform style, [[ParticleTransform.Global]] is the default and emits particles as if they were world space objects, useful for most effects.

If set to [[ParticleTransform.Local]] particles are children of the emitter and move relative to the emitter as they would in a parent/child actor relationship.

publicparticles

particles: Particle[] = []

Gets or sets the backing particle collection

publicpointer

Access to the Actor's built in [[PointerComponent]] config

publicradius

radius: number = 0

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

publicrandom

random: Random

Random number generator

publicrandomRotation

randomRotation: boolean = false

Indicates whether particles should start with a random rotation

publicscene

scene: Scene<unknown> = null

The current scene that the entity is in, if any

publicstartSize

startSize: number = null

Gets or sets the optional starting size for the particles

publictagAdded$

tagAdded$: Observable<string> = ...

publictagRemoved$

tagRemoved$: Observable<string> = ...

publictransform

Access the Actor's built in [[TransformComponent]]

publicstaticdefaults

defaults: { anchor: Vector } = ...

Set defaults for all Actors


Type declaration

Accessors

publicacc

  • 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

publicanchor

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


    Returns Vector

  • Parameters

    Returns void

publicangularVelocity

  • get angularVelocity(): number
  • set angularVelocity(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

publiccenter

  • Get the center point of an actor (global position)


    Returns Vector

publicchildren

  • get children(): readonly Entity<any>[]
  • Get the direct children of this entity


    Returns readonly Entity<any>[]

publiccolor

  • Sets the color of the actor's current graphic


    Returns Color

  • Parameters

    Returns void

publicdraggable

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

  • Parameters

    • isDraggable: boolean

    Returns void

publicheight

  • get height(): number
  • Returns number

publicisInitialized

  • get isInitialized(): boolean
  • Gets whether the actor is Initialized


    Returns boolean

publicisOffScreen

  • get isOffScreen(): boolean
  • Indicates whether the actor is physically in the viewport


    Returns boolean

publiclocalCenter

  • Get the local center point of an actor


    Returns Vector

publicoffset

  • The offset in pixels to apply to all actor graphics

    Default offset of (0, 0)


    Returns Vector

  • Parameters

    Returns void

publicoldAcc

  • 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

publicoldPos

  • 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

publicoldVel

  • 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

publicopacity

  • get opacity(): number
  • set opacity(opacity: number): void
  • Gets the opacity of each particle from 0 to 1.0


    Returns number

  • Gets the opacity of each particle from 0 to 1.0


    Parameters

    • opacity: number

    Returns void

publicparent

  • Returns Entity<any>

publicparticleSprite

  • Gets or sets the sprite that a particle should use


    Returns Graphic

  • Parameters

    Returns void

publicpos

  • Gets the position vector of the actor in pixels


    Returns Vector

  • Sets the position vector of the actor in pixels


    Parameters

    Returns void

publicrotation

  • 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

publicscale

  • Returns Vector

  • Parameters

    Returns void

publictags

  • get tags(): Set<string>
  • Specifically get the tags on the entity from [[TagsComponent]]


    Returns Set<string>

publictypes

  • The types of the components on the Entity


    Returns ComponentCtor[]

publicvel

  • 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

publicwidth

  • get width(): number
  • Returns number

publicz

  • get z(): number
  • set z(newZ: number): void
  • 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

  • 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

    • newZ: number

      new z-index to assign

    Returns void

Methods

publicaddChild

  • Adds an entity to be a child of this entity


    Parameters

    Returns Entity<any>

publicaddComponent

  • addComponent<TComponent>(component: TComponent, force?: boolean): Entity<any>
  • Adds a component to the entity


    Type parameters

    Parameters

    • component: TComponent

      Component or Entity to add copy of components from

    • force: boolean = false

      Optionally overwrite any existing components of the same type

    Returns Entity<any>

publicaddTag

  • addTag(tag: string): Entity<any>
  • Adds a tag to an entity


    Parameters

    • tag: string

    Returns Entity<any>

publicaddTemplate

  • addTemplate(templateEntity: Entity<any>, force?: boolean): Entity<any>
  • Adds a copy of all the components from another template entity as a "prefab"


    Parameters

    • templateEntity: Entity<any>

      Entity to use as a template

    • force: boolean = false

      Force component replacement if it already exists on the target entity

    Returns Entity<any>

publicclearComponents

  • clearComponents(): void
  • Returns void

publicclearParticles

  • clearParticles(): void
  • Returns void

publicclone

  • Creates a deep copy of the entity and a copy of all its components


    Returns Actor

publiccontains

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

    • recurse: boolean = false

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

    Returns boolean

publicemit

  • emit<TEventName>(eventName: TEventName, event: ActorEvents[TEventName]): void
  • emit(eventName: string, event?: any): void
  • Emits an event for target


    Type parameters

    Parameters

    • eventName: TEventName

      The name of the event to publish

    • event: ActorEvents[TEventName]

      Optionally pass an event data object to the handler

    Returns void

publicemitParticles

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


    Parameters

    • particleCount: number

      Number of particles to emit right now

    Returns void

get

publicgetAncestors

  • Returns a list of parent entities starting with the topmost parent. Includes the current entity.


    Returns Entity<any>[]

publicgetComponents

  • Returns all component instances on entity


    Returns Component[]

publicgetDescendants

  • getDescendants(): Entity<any>[]
  • Returns a list of all the entities that descend from this entity. Includes the current entity.


    Returns Entity<any>[]

publicgetGlobalPos

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


    Returns Vector

    Position in world coordinates

publicgetGlobalRotation

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


    Returns number

    Rotation angle in radians

publicgetGlobalScale

  • Gets the global scale of the Actor


    Returns Vector

publichas

  • Check if a component type exists


    Type parameters

    Parameters

    Returns boolean

hasAll

  • hasAll<TComponent>(requiredTypes: ComponentCtor<TComponent>[]): boolean
  • Verifies that an entity has all the required types


    Type parameters

    Parameters

    Returns boolean

hasAllTags

  • hasAllTags(requiredTags: string[]): boolean
  • Verifies that an entity has all the required tags


    Parameters

    • requiredTags: string[]

    Returns boolean

publichasTag

  • hasTag(tag: string): boolean
  • Check if a tag exists on the entity


    Parameters

    • tag: string

      name to check for

    Returns boolean

publicisKilled

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


    Returns boolean

publickill

  • 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

publicoff

  • off<TEventName>(eventName: TEventName, handler: Handler<ActorEvents[TEventName]>): void
  • off(eventName: string, handler: Handler<unknown>): void
  • off(eventName: string): void
  • Unsubscribe an event handler(s) from an event. If a specific handler is specified for an event, only that handler will be unsubscribed. Otherwise all handlers will be unsubscribed for that event.


    Type parameters

    Parameters

    • eventName: TEventName

      The name of the event to unsubscribe

    • handler: Handler<ActorEvents[TEventName]>

      Optionally the specific handler to unsubscribe

    Returns void

publicon

  • Subscribe an event handler to a particular event name, multiple handlers per event name are allowed.


    Type parameters

    Parameters

    • eventName: TEventName

      The name of the event to subscribe to

    • handler: Handler<ActorEvents[TEventName]>

      The handler callback to fire on this event

    Returns Subscription

publiconCollisionEnd

  • Fires once when 2 entities with a ColliderComponent separate after having been in contact.


    Parameters

    Returns void

publiconCollisionStart

  • Fires once when 2 entities with a ColliderComponent first start colliding or touching, if the Colliders stay in contact this does not continue firing until they separate and re-collide.


    Parameters

    Returns void

publiconInitialize

  • onInitialize(engine: Engine<any>): 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

publiconPostCollisionResolve

  • Fires after every resolution for a confirmed contact.


    Parameters

    Returns void

publiconPostKill

  • onPostKill(scene: Scene<unknown>): 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

publiconPostUpdate

  • onPostUpdate(engine: Engine<any>, 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<any>
    • delta: number

    Returns void

publiconPreCollisionResolve

  • Fires before every collision resolution for a confirmed contact


    Parameters

    Returns void

publiconPreKill

  • onPreKill(scene: Scene<unknown>): 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

publiconPreUpdate

  • onPreUpdate(engine: Engine<any>, 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<any>
    • delta: number

    Returns void

publiconce

  • Once listens to an event once then auto unsubscribes from that event


    Type parameters

    Parameters

    • eventName: TEventName

      The name of the event to subscribe to once

    • handler: Handler<ActorEvents[TEventName]>

      The handler of the event that will be auto unsubscribed

    Returns Subscription

publicremoveAllChildren

  • removeAllChildren(): Entity<any>
  • Removes all children from this entity


    Returns Entity<any>

publicremoveChild

  • Remove an entity from children if it exists


    Parameters

    Returns Entity<any>

publicremoveComponent

  • removeComponent<TComponent>(typeOrInstance: TComponent | ComponentCtor<TComponent>, force?: boolean): Entity<Exclude<any, TComponent>>
  • Removes a component from the entity, by default removals are deferred to the end of entity update to avoid consistency issues

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


    Type parameters

    Parameters

    • typeOrInstance: TComponent | ComponentCtor<TComponent>
    • force: boolean = false

    Returns Entity<Exclude<any, TComponent>>

publicremoveParticle

  • removeParticle(particle: Particle): void
  • Parameters

    Returns void

publicremoveTag

  • removeTag(tag: string): Entity<any>
  • Removes a tag on the entity

    Removals are deferred until the end of update


    Parameters

    • tag: string

    Returns Entity<any>

publicunkill

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


    Returns void

publicunparent

  • unparent(): void
  • Unparents this entity, if there is a parent. Otherwise it does nothing.


    Returns void

publicupdate

  • update(engine: Engine<any>, delta: number): void
  • Parameters

    • engine: Engine<any>
    • delta: number

    Returns void

publicwithin

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