1.首先定义唯一标识:
#define GAME_EVENT_PLAYER_EXP_UPDATED "player_exp_updated"
2.注册事件监听
cocos2d::EventListener* m_pPlayerExpListener;
m_pPlayerExpListener = EventListenerCustom::create(GAME_EVENT_PLAYER_EXP_UPDATED, [this](EventCustom* pEvent)
{
//do something
});
getEventDispatcher()->addEventListenerWithSceneGraphPriority(m_pPlayerExpListener, this);
3.触发事件
Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(GAME_EVENT_PLAYER_EXP_UPDATED, NULL);
原文地址:http://www.cnblogs.com/niwococo/p/3910864.html