query
query<
Cs>(…components):Query<Cs>
Defined in: query.ts:489
Creates a Query, which represents a set of criteria used to filter and iterate over entities based on their components.
Queries provide a fluent, chainable API to define strict matching rules (such as requiring or
excluding specific components) and offer various ways to consume the matching entities. You can
iterate over them (forEach, map), listen to their lifecycle events (onAdded, onChanged),
or bind them directly into optimized system callbacks (bind).
Type Parameters
Section titled “Type Parameters”Cs extends ZeroUpToEight<ComponentHandle<unknown> | Pair<unknown>>
Parameters
Section titled “Parameters”components
Section titled “components”…Cs
Returns
Section titled “Returns”Query<Cs>
Example
Section titled “Example”// 1. Define the query.const healthyMovers = query(Health, Position) .with(Velocity) .without(Stunned) .filter((_entity, health, _position) => health > 0)
// 2. Consume the query.healthyMovers.forEach((entity, health, position) => { print(`Entity ${entity.id} is moving with ${health}hp at ${position}!`)})