Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface View<T>

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:

 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) return false;
     world.create(A, B, C);
 })

Type parameters

Hierarchy

  • View

Index

Methods

Methods

each

  • Iterates over all the entities in the View.

    If you return false from the callback, the iteration will halt.

    Parameters

    Returns void

Generated using TypeDoc