Skip to content

AspectSubscriptionManager

Adrian Papari edited this page Jul 19, 2015 · 11 revisions

Retrieving all entities

AspectSubscriptionManager asm = world.getManager(AspectSubscriptionManager.class);
EntitySubscription subscription = asm.get(Aspect.all(ComponentY.class));
// don't hold onto the IntBag
IntBag entityIds = subscription.getEntities();

EntitySubscriptions can be instantiated at any time.

EntitySubscription#getEntities()

EntitySubscriptions synchronize the active entity id:s on demand; this synchronization check happens during #getEntities() - make sure to call it when processing enters a new system or manager - as all entity state changes are applied in-between processing each system.

Subscribing to inserted/removed entities

  • Implement EntitySubscription.SubscriptionListener.
  • Fetch the subscription and add the listener:
AspectSubscriptionManager asm = world.getManager(AspectSubscriptionManager.class);
EntitySubscription subscription = asm.get(Aspect.all(ComponentY.class));
subscription.addSubscriptionListener(new EntitySubscription.SubscriptionListener() {
    @Override
    public void inserted(ImmutableBag<Entity> entities) {
        // code
    }

    @Override
    public void removed(ImmutableBag<Entity> entities) {
        // code
    }
});
Clone this wiki locally