通过CCNotificationCenter传递数据
Passing data with CCNotficationCenter
我是Cocos2d-X的新手。
CCNotificationCenter::sharedNotificationCenter()->addObserver(
this,
callfuncO_selector(test::printSomething),
"hello",
NULL);
回调函数为
void PingoScreen::printSomething(CCObject *pObject) {
CCString * myData = (CCString*)pObject;
CCLog("The data posted is %s",myData);
}
现在我想通过通知发送一个CCString参数,这样
CCNotificationCenter::sharedNotificationCenter()->postNotification("hello",
ccs(notificationData));
我该怎么做?我需要更改通知定义中的哪些内容?
注册通知
CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(GameScene::doSomething), "eventNotification", NULL);
删除通知
CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, "eventNotification");
张贴通知
CCNotificationCenter::sharedNotificationCenter()->postNotification("eventNotification", myString);
回调方法
void GameScene::doSomething(CCObject *pObject) {
CCString *myString = (CCString*)pObject;
// XXX: Do something
}
相关文章:
- 防止主数据类型C++的隐式转换
- 用于访问容器<T>数据成员的正确 API
- 嵌套在类中时无法设置成员数据
- 使用流处理接收到的数据
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 在cuda线程之间共享大量常量数据
- C++将文本文件中的数据读取到结构数组中
- 如何在C++中序列化结构数据
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 通过套接字[TCP]传输数据 如何在C / C ++中打包多个整数并使用send() recv()传输数据
- 在c代码之间共享数据的最佳方式
- 链表,反向函数,数据结构
- 数据成员SFINAE的C++17测试:gcc vs clang
- C++浮点数据类型和字符串数据类型无法子到模板函数中
- 如何对点云数据进行排序
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 在运行时处理类型擦除的数据-如何不重新发明轮子