const movingEntitiesQuery = createQueryDefinition({
with: ['position', 'velocity'],
without: ['dead']
});
type MovingEntity = QueryResultEntity<Components, typeof movingEntitiesQuery>;
function updatePosition(entity: MovingEntity) {
entity.components.position.x += entity.components.velocity.x;
entity.components.position.y += entity.components.velocity.y;
}
world.addSystem('movement')
.addQuery('entities', movingEntitiesQuery)
.setProcess(({ queries }) => {
for (const entity of queries.entities) {
updatePosition(entity);
}
});
Helper function to create a query definition with proper type inference. This enables better TypeScript inference when creating reusable queries.