-
Notifications
You must be signed in to change notification settings - Fork 112
AspectSubscriptionManager
Adrian Papari edited this page Nov 26, 2019
·
11 revisions
You can subscribe to entities that match a certain Aspect. You can use this to:
- Obtain a list of matching entities
- Be informed of new entities matching the Aspect.
- Be informed of entities no longer matching the Aspect.
EntitySubscription subscription = world.getAspectSubscriptionManager()
.get(Aspect.all(ComponentX.class, ComponentY.class));
IntBag entityIds = subscription.getEntities();
Note that the bag is only valid while the system is being processed. Don't hold on to it! Also don't change the contents.
- Implement
EntitySubscription.SubscriptionListener
. - Fetch subscription and add listener.
EntitySubscription subscription = world.getAspectSubscriptionManager()
.get(Aspect.all(ComponentY.class).exclude(ComponentZ.class));
subscription.addSubscriptionListener(new EntitySubscription.SubscriptionListener() {
@Override
public void inserted(IntBag entities) {}
@Override
public void removed(IntBag entities) {}
});
See @DelayedComponentRemoval if you need to components to be readable in listeners after the user removes them.
- Overview
- Concepts
- Getting Started
- Using
- More guides
- Plugins
- Game Gallery
- Tools and Frameworks
- API reference