`
modabobo
  • 浏览: 509297 次
文章分类
社区版块
存档分类
最新评论

观察者模式

 
阅读更多
首先,要在监听模块中添加监听事件,即在onEnter()函数中
CCNotificationCenter::sharedNotificaitonCenter()->addObserver(CCObject *target,
SEL_CallFuncO selector,
const char *name,
CCObject *obj)
target为当前类的this指针,selector为事件触发时执行的函数,name是事件的名字,obj为传输的数据
同理在onExit()中要移除监听
CCNotificationCenter::sharedNotificaitonCenter()->removeObserver(CCObject *target,const char *name)
另外在条件触发处加上一句推送事件的通知
CCNotificationCenter::sharedNotificaitonCenter()->postNotification(const char *name, CCObject *object)
如此而已
网络模块也可以参照这个模式进行处理
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics