Counts entities matching a specific query.
O(1) counting via Miniplex archetype size property when available. Much faster than manually iterating and counting.
The Strata world.
Component keys to query.
Number of matching entities.
// Count all enemiesconst enemyCount = countEntities(world, 'enemy');console.log(`${enemyCount} enemies remaining`); Copy
// Count all enemiesconst enemyCount = countEntities(world, 'enemy');console.log(`${enemyCount} enemies remaining`);
// Count entities with multiple componentsconst movableCount = countEntities(world, 'position', 'velocity');// vs slower manual counting:// let count = 0;// for (const _ of world.query('position', 'velocity')) count++; Copy
// Count entities with multiple componentsconst movableCount = countEntities(world, 'position', 'velocity');// vs slower manual counting:// let count = 0;// for (const _ of world.query('position', 'velocity')) count++;
Counts entities matching a specific query.
O(1) counting via Miniplex archetype size property when available. Much faster than manually iterating and counting.