Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Entity<KnownComponents>

Type parameters

Hierarchy

Implements

Index

Constructors

constructor

Properties

active

active: boolean = true

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

changes

changes: Observable<AddedComponent | RemovedComponent> = new Observable<AddedComponent | RemovedComponent>()

components

components: ComponentMapper<KnownComponents> = new Proxy<ComponentMapper<KnownComponents>>({} as any, this._handleChanges)

eventDispatcher

eventDispatcher: EventDispatcher

Direct access to the game object event dispatcher.

id

id: number = Entity._ID++

The unique identifier for the entity

Accessors

isInitialized

  • get isInitialized(): boolean

types

  • get types(): string[]

Methods

_initialize

  • _initialize(engine: Engine): void
  • Initializes this entity, meant to be called by the Scene before first update not by users of Excalibur.

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

    internal

    Parameters

    Returns void

_postupdate

  • _postupdate(engine: Engine, delta: number): void

_preupdate

  • _preupdate(engine: Engine, delta: number): void

addComponent

  • addComponent<T>(componentOrEntity: T | Entity<T>, force?: boolean): Entity<KnownComponents | T>

clone

emit

  • emit(eventName: string, eventObject: GameEvent<any>): void

has

  • has(type: string): boolean

isKilled

  • isKilled(): boolean

kill

  • kill(): 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: string, handler: function): void
  • Alias for addEventListener. You can listen for a variety of events off of the engine; see the events section below for a complete list.

    Parameters

    • eventName: string

      Name of the event to listen for

    • handler: function

      Event handler for the thrown event

    Returns void

onInitialize

  • onInitialize(_engine: Engine): void

onPostUpdate

  • onPostUpdate(_engine: Engine, _delta: number): void

onPreUpdate

  • onPreUpdate(_engine: Engine, _delta: number): void

once

  • once(eventName: string, handler: function): void
  • Once listens to an event one time, then unsubscribes from that event

    Parameters

    • eventName: string

      The name of the event to subscribe to once

    • handler: function

      The handler of the event that will be auto unsubscribed

    Returns void

removeComponent

  • removeComponent<ComponentOrType>(componentOrType: ComponentOrType, force?: boolean): Entity<ExcludeType<KnownComponents, ComponentOrType>>
  • Removes a component from the entity, by default removals are deferred to the end of entity processing 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
    • Default value force: boolean = false

    Returns Entity<ExcludeType<KnownComponents, ComponentOrType>>