Using EventDispatcher in cocos2d-x

From: Cocos2d-x Cookbook by Akihito Matsuura (Packt Publishing, 2015)

Using EventDispatcher in cocos2d-x, we can implement Observer Pattern.

// initialize, remove all previous custom event listeners
this->getEventDispatcher()->removeCustomEventListeners("TimeCount");
// register a custom listener
this->getEventDispatcher()->addCustomEventListener("TimeCount", [=](EventCustom* event) { this->countUp(0); });
// trigger a custom event
this->getEventDistpatcher()->dispatchCustomEvent("TimeCount");