微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

cocos2dx3.x 观察者模式

在cocos2dx中封装好了观察者NotificationCenter,这个使用的非常广泛,在2.x中我已做描述,由于3.x的升级用法有了轻微的改变,所以说一下:
注册观察者:

NotificationCenter::getInstance()->addobserver(this,callfuncO_selector(HelloWorld::isSuccess),"signIn",NULL);


voidHelloWorld::isSuccess(Ref* sender){

automsg = (__String*)sender;

cclOG("msg=%s",msg->getCString());

}


设置事件发送者:

String*str =String::create("OK");

NotificationCenter::getInstance()->postNotification("signIn",str);

注销观察者:

//注销全部

()->removeAllObservers(this);

//注销特定

()->removeObservernormal; word-break:normal; color:rgb(0,);

原文地址:https://www.jb51.cc/cocos2dx/340065.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐