类似于以前的消息通知。
比如以前消息这样写
__Integer* value = __Integer::create(this->getTag());
__NotificationCenter::getInstance()->postNotification(GameEnums::TouchTag.c_str(), value);
接受
__NotificationCenter::getInstance()->addObserver(this, callfuncO_selector(GameShowLayer::TouchButton), GameEnums::TouchTag.c_str(), NULL);
现在自定义消息
int count = this->getTag();
char* buf = new char;
sprintf(buf, "%d", count);
EventCustom event(GameEnums::TouchButton);
event.setUserData(buf);
_eventDispatcher->dispatchEvent(&event);
CC_SAFE_DELETE_ARRAY(buf);
接收
auto _listener = EventListenerCustom::create(GameEnums::TouchButton, =](EventCustom* event){
char* tagvalue = (char*)(event->getUserData());
int tag = atoi(tagvalue);
CCLOG("Click the button,%i",tag);
});
_eventDispatcher->addEventListenerWithFixedPriority(_listener, 1);