Cocos2d-x-------------------------------消息机制NotificationCenter

NotificationCenter 常用函数

(1)addobserver函数订阅消息)

void addobserver(Ref * target,SEL_CallFuncO selector,const std::string & name,Ref * sender)

根据指定的target,添加观察者.

Ref *target :要订阅消息的主体

SEL_CallFuncO selector :消息回调函数

std::string & name:消息名称

Ref * sender :要传递的数据

(2)removeObserver 函数 (取消订阅

void removeObserver(Ref * target,const std::string & name)

根据指定的target 和 name 移除观察者.

Ref * target:取消订阅消息的主体

const std::string & name:消息名称

(3)postNotification函数(发布消息)

void postNotification(const std::string & name) 根据某个名字发送一个通知事件.

const std::string & name: 消息名称

void postNotification(const std::string & name,Ref * sender) 根据某个名字发送一个通知事件.

const std::string & name: 消息名称

Ref * sender: 要传输的数据

如果addobserver和postNotification函数都传递了数据,并且不是同一个数据,那将无法发布消息。

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...