Options
All
  • Public
  • Public/Protected
  • All
Menu

The most important primitive in Excalibur is an Actor. Anything that can move on the screen, collide with another Actor, respond to events, or interact with the current scene, must be an actor. An Actor must be part of a Scene for it to be drawn to the screen.

Hierarchy

Implements

Index

Constructors

constructor

Properties

active

active: boolean = true

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

childrenAdded$

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

childrenRemoved$

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

componentAdded$

componentAdded$: Util.Observable<AddedComponent> = ...

Observable that keeps track of component add or remove changes on the entity

componentRemoved$

componentRemoved$: Util.Observable<RemovedComponent> = ...

currentDrawing

currentDrawing: Drawable = null

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

deprecated

will be removed in v0.26.0

eventDispatcher

eventDispatcher: EventDispatcher<any>

Direct access to the game object event dispatcher.

frames

frames: {} = {}
deprecated

will be removed in v0.26.0

Type declaration

id

id: number = ...

The unique identifier for the entity

logger

logger: Util.Logger = ...

Convenience reference to the global logger

scene

scene: Scene = null

The scene that the actor is in

traits

traits: Trait[] = []

Modify the current actor update pipeline.

deprecated

will be removed in v0.26.0

Static defaults

defaults: { anchor: Vector } = ...

Set defaults for all Actors

Type declaration

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

actions

anchor

angularVelocity

  • 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

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.

    Returns BodyComponent

center

children

  • get children(): readonly Entity[]

collider

color

  • Sets the color of the actor's current graphic

    Returns Color

  • Sets the color of the actor's current graphic

    Parameters

    Returns void

draggable

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

events

graphics

height

  • get height(): number

isInitialized

  • get isInitialized(): boolean

isOffScreen

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

    Returns boolean

localCenter

motion

name

  • get name(): string

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

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

opacity

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

parent

pointer

pos

  • Gets the position vector of the actor in pixels

    Returns Vector

  • Sets the position vector of the actor in pixels

    Parameters

    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

scale

tags

  • get tags(): readonly string[]

transform

types

  • get types(): string[]

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

visible

  • get visible(): boolean
  • set visible(isVisible: boolean): void

width

  • get width(): number

z

  • 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

_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

    Warning only works with Flags.useLegacyDrawing() enabled

    deprecated

    Use Actor.graphics.onPostDraw, will be removed in v0.26.0

    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

    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

    Warning only works with Flags.useLegacyDrawing() enabled

    deprecated

    Use Actor.graphics.onPreDraw, will be removed in v0.26.0

    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

    Returns void

Protected _setName

  • _setName(name: string): void

addChild

addComponent

  • addComponent<T>(component: T, force?: boolean): Entity

addDrawing

addTag

addTemplate

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

    Parameters

    • templateEntity: Entity

      Entity to use as a template

    • force: boolean = false

      Force component replacement if it aleady exists on the target entity

    Returns Entity

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)

    • recurse: boolean = false

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

    Returns boolean

debugDraw

  • debugDraw(_ctx: CanvasRenderingContext2D): void
  • Called by the Engine, draws the actors debugging to the screen

    deprecated

    will be removed in v0.26.0

    internal

    Parameters

    • _ctx: CanvasRenderingContext2D

    Returns void

draw

  • draw(ctx: CanvasRenderingContext2D, delta: number): void
  • Called by the Engine, draws the actor to the screen

    deprecated

    Use Actor.graphics, will be removed in v0.26.0

    Parameters

    • ctx: CanvasRenderingContext2D

      The rendering context

    • delta: number

      The time since the last draw in milliseconds

      Warning only works with Flags.useLegacyDrawing() enabled

    Returns void

emit

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

    Parameters

    • eventName: string

      Name of the event to emit

    • eventObject: any

      Data associated with this event

    Returns void

get

getAncestors

getComponents

getDescendants

getGlobalPos

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

    Returns Vector

    Position in world coordinates

getGlobalRotation

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

    Returns number

    Rotation angle in radians

getGlobalScale

getZIndex

  • getZIndex(): number

has

  • has<T>(type: ComponentCtor<T>): boolean
  • has(type: string): boolean

hasTag

  • hasTag(tag: 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

on

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.

    Warning only works with Flags.useLegacyDrawing() enabled

    deprecated

    Use Actor.graphics.onPostDraw, will be removed in v0.26.0

    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

    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.

    Warning only works with Flags.useLegacyDrawing() enabled

    deprecated

    Use Actor.graphics.onPostDraw, will be removed in v0.26.0

    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

    Returns void

once

removeAllChildren

removeChild

removeComponent

  • removeComponent<ComponentOrType>(componentOrType: ComponentOrType, force?: boolean): Entity
  • 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

    • componentOrType: ComponentOrType
    • force: boolean = false

    Returns Entity

removeTag

  • removeTag(tag: string, force?: boolean): Entity

setDrawing

  • setDrawing(key: string): void
  • setDrawing(key: number): void

setZIndex

  • setZIndex(newIndex: number): void
  • deprecated

    Use Actor.z, will be removed in v0.26.0

    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

unparent

  • unparent(): void

update

  • update(engine: Engine, delta: number): void
  • Called by the Engine, updates the state of the actor

    internal

    Parameters

    • engine: Engine

      The reference to the current game engine

    • delta: number

      The time elapsed since the last update in milliseconds

    Returns void

within

  • 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