Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Actor

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.

Basic actors

For quick and dirty games, you can just create an instance of an Actor and manipulate it directly.

Actors (and other entities) must be added to a Scene to be drawn and updated on-screen.

const player = new ex.Actor();

// move the player
player.vel.x = 5;

// add player to the current scene
game.add(player);

game.add is a convenience method for adding an Actor to the current scene. The equivalent verbose call is game.currentScene.add.

Actor Lifecycle

An actor has a basic lifecycle that dictates how it is initialized, updated, and drawn. Once an actor is part of a scene, it will follow this lifecycle.

Actor Lifecycle

Extending actors

For "real-world" games, you'll want to extend the Actor class. This gives you much greater control and encapsulates logic for that actor.

You can override the onInitialize method to perform any startup logic for an actor (such as configuring state). onInitialize gets called once before the first frame an actor is drawn/updated. It is passed an instance of Engine to access global state or perform coordinate math.

TypeScript

class Player extends ex.Actor {
  public level = 1;
  public endurance = 0;
  public fortitude = 0;

  constructor() {
    super();
  }

  public onInitialize(engine: ex.Engine) {
    this.endurance = 20;
    this.fortitude = 16;
  }

  public getMaxHealth() {
    return 0.4 * this.endurance + 0.9 * this.fortitude + this.level * 1.2;
  }
}

Javascript

In Javascript you can use the extend method to override or add methods to an Actor.

var Player = ex.Actor.extend({
  level: 1,
  endurance: 0,
  fortitude: 0,

  onInitialize: function(engine) {
    this.endurance = 20;
    this.fortitude = 16;
  },

  getMaxHealth: function() {
    return 0.4 * this.endurance + 0.9 * this.fortitude + this.level * 1.2;
  }
});

Updating actors

Override the update method to update the state of your actor each frame. Typically things that need to be updated include state, drawing, or position.

Remember to call super.update to ensure the base update logic is performed. You can then write your own logic for what happens after that.

The update method is passed an instance of the Excalibur engine, which can be used to perform coordinate math or access global state. It is also passed delta which is the time in milliseconds since the last frame, which can be used to perform time-based movement or time-based math (such as a timer).

TypeScript

class Player extends Actor {
  public update(engine: ex.Engine, delta: number) {
    super.update(engine, delta); // call base update logic

    // check if player died
    if (this.health <= 0) {
      this.emit('death');
      this.onDeath();
      return;
    }
  }
}

Javascript

var Player = ex.Actor.extend({
  update: function(engine, delta) {
    ex.Actor.prototype.update.call(this, engine, delta); // call base update logic

    // check if player died
    if (this.health <= 0) {
      this.emit('death');
      this.onDeath();
      return;
    }
  }
});

Drawing actors

Override the draw method to perform any custom drawing. For simple games, you don't need to override draw, instead you can use addDrawing and setDrawing to manipulate the sprites/animations that the actor is using.

Working with Textures & Sprites

Think of a texture as the raw image file that will be loaded into Excalibur. In order for it to be drawn it must be converted to a Sprite.

A common usage is to load a Texture and convert it to a Sprite for an actor. If you are using the Loader to pre-load assets, you can simply assign an actor a Sprite to draw. You can also create a sprite from a Texture to quickly create a Sprite instance.

// assume Resources.TxPlayer is a 80x80 png image

public onInitialize(engine: ex.Engine) {

   // set as the "default" drawing
   this.addDrawing(Resources.TxPlayer);

   // you can also set a Sprite instance to draw
   this.addDrawing(Resources.TxPlayer.asSprite());
}

Working with Animations

A SpriteSheet holds a collection of sprites from a single Texture. Use SpriteSheet.getAnimationForAll to easily generate an Animation.

// assume Resources.TxPlayerIdle is a texture containing several frames of an animation

public onInitialize(engine: ex.Engine) {

   // create a SpriteSheet for the animation
   const playerIdleSheet = new ex.SpriteSheet(Resources.TxPlayerIdle, 5, 1, 80, 80);

   // create an animation
   const playerIdleAnimation = playerIdleSheet.getAnimationForAll(engine, 120);

   // the first drawing is always the current
   this.addDrawing("idle", playerIdleAnimation);
}

Custom drawing

You can always override the default drawing logic for an actor in the draw method, for example, to draw complex shapes or to use the raw Canvas API.

Usually you should call super.draw to perform the base drawing logic, but other times you may want to take over the drawing completely.

public draw(ctx: CanvasRenderingContext2D, delta: number) {

   super.draw(ctx, delta); // perform base drawing logic

   // custom drawing
   ctx.lineTo(...);
}

Actions

You can use the Action API to create chains of actions and script actors into doing your bidding for your game.

Actions can be simple or can be chained together to create complex AI routines. In the future, it will be easier to create timelines or scripts to run depending on the state of your actor, such as an enemy ship that is Guarding a path and then is Alerted when a Player draws near.

Learn more about the Action API.

Collision Detection

By default Actors do not participate in collisions. If you wish to make an actor participate, you need to switch from the default prevent collision to active, fixed, or passive collision type.

For more information on collisions, please read about rigid body physics.

public Player extends ex.Actor {
   constructor() {
      super();
      // set preferred CollisionType
      this.body.collider.type = ex.CollisionType.Active;
   }
}

// or set the collisionType

const actor = new ex.Actor();
actor.body.collider.type = ex.CollisionType.Active;

Traits

Traits describe actor behavior that occurs every update. If you wish to build a generic behavior without needing to extend every actor you can do it with a trait, a good example of this may be plugging in an external collision detection library like Box2D or PhysicsJS by wrapping it in a trait. Removing traits can also make your actors more efficient.

Default traits provided by Excalibur are pointer capture, tile map collision, and offscreen culling.

Constructor Arguments

In Excalibur there are option bag constructors available on most types. These support any public property or member, methods are not supported. The API documentation does not provide an exhaustive list of possible properties but a list of commonly used properties.

For example instead of doing this:

const actor = new ex.Actor(1, 2, 100, 100, ex.Color.Red);
actor.body.collider.type = ex.CollisionType.Active;

This is possible:

const options: IActorArgs = {
   pos: new ex.Vector(1,2);
   width: 100,
   height: 100,
   color: ex.Color.Red,
}

const actor = new ex.Actor(options);
actor.body.collider.type = ex.CollisionType.Active;

In fact you can create a duplicate this way

const actor = new ex.Actor({
  pos: new ex.Vector(1, 2)
});
const actorClone = new ex.Actor(actor);

expect(actor.pos).toBe(actorClone.pos); // true;

Types that support option bags can have their properties mass assigned using the assign method.

const actor = new ex.Actor(options);

actor.assign({
  pos: new ex.Vector(100, 100),
  width: 1000,
  color: ex.Color.Red
});

See:

Hierarchy

Implements

Index

Constructors

constructor

  • new Actor(): Actor
  • new Actor(config?: ActorArgs): Actor
  • new Actor(x?: number, y?: number, width?: number, height?: number, color?: Color): Actor

Properties

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

children

children: Actor[] = []

The children of this actor

currentDrawing

currentDrawing: Drawable = null

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

enableCapturePointer

enableCapturePointer: boolean = false

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

eventDispatcher

eventDispatcher: EventDispatcher

Direct access to the game object event dispatcher.

frames

frames: object

Type declaration

id

id: number = ActorImpl.maxId++

The unique identifier for the actor

isOffScreen

isOffScreen: boolean = false

Indicates whether the actor is physically in the viewport

logger

logger: Logger = Logger.getInstance()

Convenience reference to the global logger

opacity

opacity: number = 1

The opacity of an actor. Passing in a color in the constructor will use the color's opacity.

parent

parent: Actor = null

The parent of this actor

previousOpacity

previousOpacity: number = 1

scene

scene: Scene = null

The scene that the actor is in

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
  • Gets whether the actor is Initialized

    Returns 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

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 <a href="_actor.actor.html#onpostdraw">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 <a href="_actor.actor.html#onpostkill">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 <a href="_actor.actor.html#onpostupdate">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 <a href="_actor.actor.html#onpredraw">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 <a href="_actor.actor.html#onprekill">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 <a href="_actor.actor.html#onpreupdate">onPreUpdate lifecycle event

    internal

    Parameters

    • engine: Engine
    • delta: number

    Returns void

Protected _reapplyEffects

  • _reapplyEffects(drawing: Drawable): 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

addDrawing

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

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, delta: number): void
  • Called by the Engine, draws the actor to the screen

    Parameters

    • ctx: CanvasRenderingContext2D

      The rendering context

    • delta: number

      The time since the last draw in milliseconds

    Returns void

emit

  • emit(eventName: string, eventObject: GameEvent<any>): 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

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

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
  • Called by the Engine, updates the state of the actor

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