It is used to efficiently iterate over large batches of entities,
and their components.
A view is lazy, which means that it fetches entities and components
just before they're passed into the callback.
The callback may return false, in which case the iteration will halt early.
This means you should avoid adding entities into the world, which have the same components
as the ones you're currently iterating over, unless you add a base case to your callback:
world.view(A, B, C).each((entity, a, b, c) => {// our arbitrary base case is reaching entity #1000// without this, the iteration would turn into an infinite loop.if (entity === 1000) returnfalse;world.create(A, B, C); })
A view is a non-owning entity iterator.
It is used to efficiently iterate over large batches of entities, and their components.
A view is lazy, which means that it fetches entities and components just before they're passed into the callback.
The callback may return false, in which case the iteration will halt early.
This means you should avoid adding entities into the world, which have the same components as the ones you're currently iterating over, unless you add a base case to your callback: