dacha
    Preparing search index...

    Class Actor

    An Actor is the main entity type in the game engine.

    Actors are entities that can have components attached to them and represent various game objects such as players, enemies, items, decorations, etc. They support hierarchical relationships and can be organized in parent-child structures.

    Hierarchy (View Summary)

    Index
    • Creates a new Actor instance.

      Parameters

      • options: ActorOptions

        Configuration options for the actor

      Returns Actor

    children: Actor[]

    Children of the entity

    id: string

    Id of the entity

    name: string

    Name of the entity

    parent: Scene | Actor | null

    Parent of the entity

    templateId?: string

    The template id of the actor

    • Adds an event listener to the event target.

      Type Parameters

      Parameters

      • type: T

        Type of event to listen for

      • callback: ActorListenerFn<T>

        Function to call when the event is triggered

      Returns void

    • Adds a child to the entity.

      Parameters

      • child: Actor

        Child to add

      Returns void

    • Dispatches an event to the event target.

      Events are processed in the engine event queue at the beginning of each frame in order that they were dispatched.

      Type Parameters

      Parameters

      • type: T

        Type of event to dispatch

      • ...payload: EventPayload<ActorEventMap, T>

        Payload of the event

      Returns void

    • Dispatches an event to the event target immediately.

      Events are processed immediately and not added to the engine event queue.

      Type Parameters

      Parameters

      • type: T

        Type of event to dispatch

      • ...payload: EventPayload<ActorEventMap, T>

        Payload of the event

      Returns void

    • Finds a child entity by a predicate function.

      Parameters

      • predicate: (child: Actor) => boolean

        A function that runs on each child entity and should return true if the child entity matches the predicate or false otherwise

      • recursive: boolean = true

        Whether to search recursively through the children

      Returns Actor | undefined

      Child entity or undefined

    • Finds a child entity by its id.

      Parameters

      • id: string

        Id of the child entity

      • recursive: boolean = true

        Whether to search recursively through the children

      Returns Actor | undefined

      Child entity or undefined

    • Finds a child entity by its name.

      Parameters

      • name: string

        Name of the child entity

      • recursive: boolean = true

        Whether to search recursively through the children

      Returns Actor | undefined

      Child entity or undefined

    • Gets a specific component from this actor.

      Type Parameters

      Parameters

      Returns T

      The component instance, or undefined if not found

      // Get by class
      const transform = actor.getComponent(Transform);

      // Get by name
      const sprite = actor.getComponent('Sprite');

      // Type-safe access
      if (transform) {
      transform.world.position.x = 100;
      }
    • Gets all components attached to this actor.

      Returns Component[]

      An array of all components

    • Removes the entity from its parent.

      Returns void

    • Removes all event listeners from the event target.

      Returns void

    • Removes a child from the entity.

      Parameters

      • child: Actor

        Child to remove

      Returns void

    • Removes a component from this actor.

      Parameters

      Returns void

      actor.removeComponent(Transform);
      
    • Removes an event listener from the event target.

      Type Parameters

      Parameters

      • type: T

        Type of event to remove the listener for

      • callback: ActorListenerFn<T>

        Function to remove the listener for

      Returns void

    • Attaches a component to this actor.

      Parameters

      • component: Component

        The component to attach

      Returns void

      const transform = new Transform({
      offset: { x: 100, y: 200 },
      rotation: 0,
      scale: { x: 1, y: 1 }
      });
      actor.setComponent(transform);