Querying Components
Learn about how to obtain lists of entities that have components in common, to make checking or updating them easier.
for (const [entity] of engine.getEntitiesWith(Transform)) {
//...
}Required components
for (const [entity] of engine.getEntitiesWith(
Transform,
Physics,
NextPosition
)) {
//...
}Use queries in a system
// Define a System
function PhysicsSystem(dt: number) {
// query for entities that include both a Transform and a Physics component
for (const [entity] of engine.getEntitiesWith(Transform, Physics)) {
const transform = Transform.getMutable(entity)
cons vel = Physics.get(entity).velocity
position.x += vel.x
position.y += vel.y
position.z += vel.z
}
}
// Add the system to the engine
engine.addSystem(rotationSystem)
Dealing with the entities and components
Subscribe to changes
Last updated