Skip to main content

Query <TKnownComponentCtors>

Represents query for entities that match a list of types that is cached and observable

Queries can be strongly typed by supplying a type union in the optional type parameter

const queryAB = new ex.Query<ComponentTypeA | ComponentTypeB>(['A', 'B']);

Index

Constructors

constructor

  • new Query<TKnownComponentCtors>(requiredComponents: TKnownComponentCtors[]): Query<TKnownComponentCtors>
  • Type parameters

    Parameters

    • requiredComponents: TKnownComponentCtors[]

    Returns Query<TKnownComponentCtors>

Properties

publiccomponents

components: Set<TKnownComponentCtors> = ...

publicentities

entities: Entity<ComponentInstance<TKnownComponentCtors>>[] = []

publicentityAdded$

entityAdded$: Observable<Entity<ComponentInstance<TKnownComponentCtors>>> = ...

This fires right after the component is added

publicentityRemoved$

entityRemoved$: Observable<Entity<ComponentInstance<TKnownComponentCtors>>> = ...

This fires right before the component is actually removed from the entity, it will still be available for cleanup purposes

publicreadonlyid

id: string

publicreadonlyrequiredComponents

requiredComponents: TKnownComponentCtors[]

Methods

checkAndAdd

  • checkAndAdd(entity: Entity<any>): boolean
  • Potentially adds an entity to a query index, returns true if added, false if not


    Parameters

    Returns boolean

publicgetEntities

  • Returns a list of entities that match the query


    Parameters

    • optionalsort: (a: Entity<any>, b: Entity<any>) => number

      Optional sorting function to sort entities returned from the query

    Returns Entity<ComponentInstance<TKnownComponentCtors>>[]

removeEntity

  • removeEntity(entity: Entity<any>): void
  • Parameters

    Returns void

staticcreateId

  • createId(requiredComponents: Function[]): string
  • Parameters

    • requiredComponents: Function[]

    Returns string