bitbrain / braingdx

:video_game: Game jam framework based on libgdx.
Apache License 2.0
84 stars 1 forks source link

Implement simple Event System #97

Closed bitbrain closed 6 years ago

bitbrain commented 6 years ago

Instead of defining indivual listeners per game component, have a so called EventManager:

EventManager eventManager = context.getEventManager();

It is the possible to implement custom events:

class MyTestEvent implements GameEvent { }

In order to produce:

eventManager.publish(new MyTestEvent());

In order to consume:

eventManager.register(new GameEventListener<MyTestEvent>() {
   @Override
   public void onEvent(MyTestEvent event) {
      // do something with the event
   }
});