Notification Center

After scratching my head for a while looking for a reason why cocos2d-x’s latest version deprecates NotificationCenter (formerly known as CCNotificationCenter), I found this thread in the issues section.

Apparently, the NotificationCenter was deprecated in favor of the new EventDispatcher class, which handles every single event you can think of, from keyboard strokes, touches, actions, … you name it.

So, the new way to do notification thingies is:

Director::getInstance()
  ->getEventDispatcher()
  ->dispatchCustomEvent("This is an event!");

Of course, this is a bit ridiculous to type all over the place, so we #define it:

#define gEventDispatcher Director::getInstance()->getEventDispatcher()

// Much better:
gEventDispatcher->dispatchCustomEvent("This is an event!");