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

      Returns Actor

    children: Actor[]

    Children of the entity

    id: string

    Id of the entity

    name: string

    Name of the entity

    parent: Actor | Scene | null

    Parent of the entity

    templateId?: string

    The template id of the actor

    • Adds a child to the entity.

      Parameters

      • child: Actor

        Child to add

      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<object>[]

      An array of all components

    • Removes the entity from its parent.

      Returns void

    • Advanced

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