dacha
    Preparing search index...

    Class ActorQuery

    A query system that automatically tracks actors matching specific criteria.

    ActorQuery provides real-time filtering and tracking of actors in a scene based on component presence or custom logic. It automatically updates when actors are added, removed, or have components added/removed.

    // Query all actors with Transform and Sprite components
    const query = new ActorQuery({
    scene: myScene,
    filter: [Transform, Sprite]
    });

    // Listen for actors being added to the query
    query.addEventListener(AddActor, ({ actor }) => {
    console.log('New actor added:', actor.name);
    });

    // Get all currently matching actors
    const actors = query.getActors();

    for (const actor of actors) {
    console.log('Actor:', actor.name);
    }

    Hierarchy (View Summary)

    Index
    parent: EventTarget | null

    Parent event target

    • Adds an event listener to the event target.

      Type Parameters

      Parameters

      • type: T

        Type of event to listen for

      • callback: ActorQueryListenerFn<T>

        Function to call when the event is triggered

      Returns void

    • Destroys the query and removes all event listeners.

      Call this method when the query is no longer needed to prevent memory leaks.

      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.

      Parameters

      • type: EventType

        Type of event to dispatch

      • Optionalpayload: Record<string, unknown>

        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.

      Parameters

      • type: EventType

        Type of event to dispatch

      • Optionalpayload: Record<string, unknown>

        Payload of the event

      Returns void

    • Gets all actors currently matching the query criteria.

      Returns Set<Actor>

      A Set of all actors that match the query filter

      const query = new ActorQuery({
      scene: myScene,
      filter: [Transform, Sprite]
      });

      // Get all matching actors
      const actors = query.getActors();
      console.log(`Found ${actors.size} actors with Transform and Sprite`);
    • Removes an event listener from the event target.

      Type Parameters

      Parameters

      • type: T

        Type of event to remove the listener for

      • callback: ActorQueryListenerFn<T>

        Function to remove the listener for

      Returns void