Options
All
  • Public
  • Public/Protected
  • All
Menu

Class UIActor

Helper Actor primitive for drawing UI's, optimized for UI drawing. Does not participate in collisions. Drawn on top of all other actors.

Hierarchy

Implements

Index

Constructors

constructor

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

    • Optional x: number

      The starting x coordinate of the actor

    • Optional y: number

      The starting y coordinate of the actor

    • Optional width: number

      The starting width of the actor

    • Optional height: number

      The starting height of the actor

    Returns UIActor

Properties

Protected _engine

_engine: Engine

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

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.

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

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

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

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

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, useWorld?: boolean): boolean
  • Parameters

    • x: number
    • y: number
    • Default value useWorld: boolean = true

    Returns boolean

debugDraw

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

    Parameters

    • ctx: CanvasRenderingContext2D

      The rendering context

    Returns 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): void
  • Emits a new event

    Parameters

    • eventName: string

      Name of the event to emit

    • Optional eventObject: GameEvent

      Data associated with this event

    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

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

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