Skip to content
Daan van Yperen edited this page Aug 2, 2014 · 6 revisions

Subscribing to events

Creating a listener

Checklist:

  • Public
  • Annotated with @Subscribe
  • Exactly one parameter derived from Event class.
@Subscribe
public void myCustomListener( MyEvent event )
{
   ..
}

Listener and event superclasses

You can catch more than one event type by using an event superclass as parameter.

If PlayerDeathEvent and MonsterDeathEvent extend DeathEvent, they will both trigger public void myCustomListener( DeathEvent event )

Listeners in Systems or Managers

Provided the EventManager is part of your World, all listeners on system and manager classes are be automatically registered upon world initialization.

Systems or managers added to a world after initialization must be manually registered. see 'Listeners on other objects' below.

Listeners on other objects

Listeners on an object outside Artemis are supported. They are resolved with the active ListenerFinderStrategy.

eventManager.registerEvents(myObject);