Cocos2d-x-------------------------------消息机制NotificationCenter
2015-08-31 17:16
585 查看
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函数都传递了数据,并且不是同一个数据,那将无法发布消息。
(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函数都传递了数据,并且不是同一个数据,那将无法发布消息。
相关文章推荐
- 如何解决cocos2dx 在android系统的音效bug
- cocos2dx lambda表达式的应用
- Cocos2d-x-------------------------定时器schedule
- 【Cocos2dx】基本动作、动作序列与动作合并
- Cocos2d-x从入门到精通第六课《自定义绘制》
- COCOS2dx 3.5 实现带白色边框圆形头像功能
- cocos2dx value vector map
- Cocos2d-x从入门到精通第五课《Cocos2d-x中的Node》
- cocos2d-x 延迟执行一段代码1 顺序执行动作+延迟动作+CallFunc
- cocos环境搭建问题
- cocos2dx 坐标系
- Cocos2D-X屏幕适配新解
- cocos2d-x 3.4版本游戏打包AKP (重点记录如何解决打包过程中遇到的各种问题)
- cocos2d-x 百分比动作2 Progress水平模式
- cocos2dx 屏幕适配
- cocos2d-x 播放帧动画
- cocos2dx新建工程分析
- cocos2dx 玩转震动
- cocos2d-x 百分比动作1 Progress半径模式
- 再探cocos2d-x------(3)