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

publicentitiesSet

entitiesSet: Set<QueryEntity<TAllComponentCtors, TAnyComponentCtors>> = ...

publicentityAdded$

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

This fires right after the component or tag is added

publicentityRemoved$

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

This fires right before the component or tag 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

Accessors

publicentities

  • get entities(): QueryEntity<TAllComponentCtors, TAnyComponentCtors>[]
  • Returns QueryEntity<TAllComponentCtors, TAnyComponentCtors>[]

Methods

checkAndModify

  • Potentially adds or removes an entity from a query index, returns true if added, false if not added or was removed.


    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

    matchesNotFilter

    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