The actor controlled by the player.

Hierarchy (view full)

Constructors

Properties

_state: PlayerState = ...
active: boolean

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

childrenAdded$: Observable<Entity>
childrenRemoved$: Observable<Entity>
componentAdded$: Observable<AddedComponent>

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

componentRemoved$: Observable<RemovedComponent>
dying: boolean = false
events: EventEmitter<ActorEvents>
id: number

The unique identifier for the entity

initialState?: ActorState
logger: Logger

Convenience reference to the global logger

scene: Scene<unknown>

The scene that the entity is in, if any

defaults: {
    anchor: Vector;
}

Set defaults for all Actors

Type declaration

  • anchor: Vector

Accessors

  • get acc(): Vector
  • 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

  • set acc(theAcc): void
  • Sets the acceleration vector of teh actor in pixels/second/second

    Parameters

    • theAcc: Vector

    Returns void

  • get actions(): ActionsComponent
  • 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.

    Returns ActionsComponent

  • get anchor(): Vector
  • Returns Vector

  • set anchor(vec): void
  • Parameters

    • vec: Vector

    Returns void

  • get angularVelocity(): number
  • Gets the rotational velocity of the actor in radians/second

    Returns number

  • set angularVelocity(angularVelocity): void
  • Sets the rotational velocity of the actor in radians/sec

    Parameters

    • angularVelocity: number

    Returns void

  • get body(): BodyComponent
  • 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

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

    Returns Vector

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

    Returns readonly Entity[]

  • get collider(): ColliderComponent
  • Access to the Actor's built in [[ColliderComponent]]

    Returns ColliderComponent

  • get color(): Color
  • Sets the color of the actor's current graphic

    Returns Color

  • set color(v): void
  • Parameters

    • v: Color

    Returns void

  • get draggable(): boolean
  • Returns boolean

  • set draggable(isDraggable): void
  • Parameters

    • isDraggable: boolean

    Returns void

  • get graphics(): GraphicsComponent
  • Access to the Actor's built in [[GraphicsComponent]]

    Returns GraphicsComponent

  • get height(): number
  • Returns number

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

    Returns boolean

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

    Returns boolean

  • get localCenter(): Vector
  • Get the local center point of an actor

    Returns Vector

  • get motion(): MotionComponent
  • Access the Actor's built in [[MotionComponent]]

    Returns MotionComponent

  • get name(): string
  • Returns string

  • get oldAcc(): Vector
  • Gets the acceleration of the actor from the last frame. This does not include the global acc [[Physics.acc]].

    Returns Vector

  • set oldAcc(theAcc): void
  • Sets the acceleration of the actor from the last frame. This does not include the global acc [[Physics.acc]].

    Parameters

    • theAcc: Vector

    Returns void

  • get oldPos(): Vector
  • Gets the position vector of the actor from the last frame

    Returns Vector

  • set oldPos(thePos): void
  • Sets the position vector of the actor in the last frame

    Parameters

    • thePos: Vector

    Returns void

  • get oldVel(): Vector
  • Gets the velocity vector of the actor from the last frame

    Returns Vector

  • set oldVel(theVel): void
  • Sets the velocity vector of the actor from the last frame

    Parameters

    • theVel: Vector

    Returns void

  • get parent(): Entity
  • Returns Entity

  • get pointer(): PointerComponent
  • Access to the Actor's built in [[PointerComponent]] config

    Returns PointerComponent

  • get pos(): Vector
  • Gets the position vector of the actor in pixels

    Returns Vector

  • set pos(thePos): void
  • Sets the position vector of the actor in pixels

    Parameters

    • thePos: Vector

    Returns void

  • get rotation(): number
  • Gets the rotation of the actor in radians. 1 radian = 180/PI Degrees.

    Returns number

  • set rotation(theAngle): void
  • Sets the rotation of the actor in radians. 1 radian = 180/PI Degrees.

    Parameters

    • theAngle: number

    Returns void

  • get scale(): Vector
  • Returns Vector

  • set scale(scale): void
  • Parameters

    • scale: Vector

    Returns void

  • get tags(): readonly string[]
  • Specifically get the tags on the entity from [[TagComponent]]

    Returns readonly string[]

  • get transform(): TransformComponent
  • Access the Actor's built in [[TransformComponent]]

    Returns TransformComponent

  • get types(): string[]
  • The types of the components on the Entity

    Returns string[]

  • get vel(): Vector
  • Gets the velocity vector of the actor in pixels/sec

    Returns Vector

  • set vel(theVel): void
  • Sets the velocity vector of the actor in pixels/sec

    Parameters

    • theVel: Vector

    Returns void

  • get width(): number
  • Returns number

  • get z(): 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

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

    • newZ: number

      new z-index to assign

    Returns void

Methods

  • Internal

    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.

    Parameters

    • engine: Engine

    Returns void

  • Internal

    It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _prekill handler for [[onPostKill]] lifecycle event

    Parameters

    • _scene: Scene<unknown>

    Returns void

  • Internal

    It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _preupdate handler for [[onPostUpdate]] lifecycle event

    Parameters

    • engine: Engine
    • delta: number

    Returns void

  • Internal

    It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _prekill handler for [[onPreKill]] lifecycle event

    Parameters

    • _scene: Scene<unknown>

    Returns void

  • Internal

    It is not recommended that internal excalibur methods be overridden, do so at your own risk.

    Internal _preupdate handler for [[onPreUpdate]] lifecycle event

    Parameters

    • engine: Engine
    • delta: number

    Returns void

  • Parameters

    • name: string

    Returns void

  • Adds an entity to be a child of this entity

    Parameters

    • entity: Entity

    Returns Entity

  • Adds a component to the entity

    Type Parameters

    • T extends Component<string>

    Parameters

    • component: T

      Component or Entity to add copy of components from

    • Optional force: boolean

      Optionally overwrite any existing components of the same type

    Returns Entity

  • Adds a tag to an entity

    Parameters

    • tag: string

    Returns Entity

    Entity

  • Adds a copy of all the components from another template entity as a "prefab"

    Parameters

    • templateEntity: Entity

      Entity to use as a template

    • Optional force: boolean

      Force component replacement if it already exists on the target entity

    Returns Entity

  • Returns void

  • Returns Actor

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

    • Optional recurse: boolean

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

    Returns boolean

  • Type Parameters

    • TEventName extends EventKey<ActorEvents>

    Parameters

    Returns void

  • Parameters

    • eventName: string
    • Optional event: any

    Returns void

  • Get a component by type with typecheck

    (Does not work on tag components, use .hasTag("mytag") instead)

    Type Parameters

    • T extends Component<string>

    Parameters

    • type: ComponentCtor<T>

    Returns null | T

  • Type Parameters

    • T extends Component<string>

    Parameters

    • type: string

    Returns null | T

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

    Returns Entity[]

  • Returns Component<string>[]

  • Returns a list of all the entities that descend from this entity. Includes the current entity.

    Returns Entity[]

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

    Returns Vector

    Position in world coordinates

  • Gets this actor's rotation taking into account any parent relationships

    Returns number

    Rotation angle in radians

  • Gets the global scale of the Actor

    Returns Vector

  • Check if a component type exists

    Type Parameters

    • T extends Component<string>

    Parameters

    • type: ComponentCtor<T>

    Returns boolean

  • Parameters

    • type: string

    Returns boolean

  • Check if a tag exists on the entity

    Parameters

    • tag: string

      name to check for

    Returns boolean

  • Indicates wether the actor has been killed.

    Returns boolean

  • Parameters

    • seconds: number
    • Optional respawn: number
    • Optional cb: (() => void)
        • (): void
        • Returns void

    Returns boolean

  • Type Parameters

    • TEventName extends EventKey<ActorEvents>

    Parameters

    Returns void

  • Parameters

    • eventName: string
    • handler: Handler<unknown>

    Returns void

  • Parameters

    • eventName: string

    Returns void

  • Type Parameters

    • TEventName extends EventKey<ActorEvents>

    Parameters

    Returns Subscription

  • Parameters

    • eventName: string
    • handler: Handler<unknown>

    Returns Subscription

  • 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

    • engine: Engine

    Returns 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

    • _scene: Scene<unknown>

    Returns 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

  • 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

    • _scene: Scene<unknown>

    Returns 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

  • Type Parameters

    • TEventName extends EventKey<ActorEvents>

    Parameters

    Returns Subscription

  • Parameters

    • eventName: string
    • handler: Handler<unknown>

    Returns Subscription

  • Removes all children from this entity

    Returns Entity

  • Remove an entity from children if it exists

    Parameters

    • entity: Entity

    Returns 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

    • ComponentOrType extends string | Component<string>

    Parameters

    Returns Entity

  • Removes a tag on the entity

    Removals are deferred until the end of update

    Parameters

    • tag: string
    • Optional force: boolean

      Remove component immediately, no deferred

    Returns Entity

  • If the current actor is killed, it will now not be killed.

    Returns void

  • Unparents this entity, if there is a parent. Otherwise it does nothing.

    Returns void

  • Internal

    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

  • 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

Generated using TypeDoc