Skip to main content

Query <TAllComponentCtors, TAnyComponentCtors>

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<TAllComponentCtors, TAnyComponentCtors>(params: TAllComponentCtors[] | QueryParams<TAllComponentCtors, TAnyComponentCtors>): Query<TAllComponentCtors, TAnyComponentCtors>

Properties

publicentities

entities: QueryEntity<TAllComponentCtors, TAnyComponentCtors>[] = []

publicentityAdded$

entityAdded$: Observable<QueryEntity<TAllComponentCtors, TAnyComponentCtors>> = ...

This fires right after the component is added

publicentityRemoved$

entityRemoved$: Observable<QueryEntity<TAllComponentCtors, TAnyComponentCtors>> = ...

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

publicreadonlyfilter

filter: { components: { all: Set<TAllComponentCtors>; any: Set<TAnyComponentCtors>; not: Set<ComponentCtor<Component>> }; tags: { all: Set<string>; any: Set<string>; not: Set<string> } } = ...

Type declaration

  • components: { all: Set<TAllComponentCtors>; any: Set<TAnyComponentCtors>; not: Set<ComponentCtor<Component>> }
  • tags: { all: Set<string>; any: Set<string>; not: Set<string> }
    • all: Set<string>
    • any: Set<string>
    • not: Set<string>

publicreadonlyid

id: string

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

  • getEntities(sort?: (a: Entity<any>, b: Entity<any>) => number): QueryEntity<TAllComponentCtors, TAnyComponentCtors>[]
  • 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 QueryEntity<TAllComponentCtors, TAnyComponentCtors>[]

    matches

    • matches(entity: Entity<any>): boolean
    • Parameters

      Returns boolean

    removeEntity

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

      Returns void

    staticcreateId

    • createId(params: Function[] | QueryParams<any, any>): string
    • Parameters

      Returns string

    statichashComponents

    statichashTags

    • hashTags(set: Set<string>): string
    • Parameters

      • set: Set<string>

      Returns string