使用CCNotficationCenter传递数据 [英] Passing data with CCNotficationCenter
本文介绍了使用CCNotficationCenter传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Cocos2d-X的新手。
I am new to 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参数,以便
Now i want to send a CCString parameter via notification so that
CCNotificationCenter::sharedNotificationCenter()->postNotification("hello",
ccs(notificationData));
我该如何做?我需要在通知定义中更改什么?
How can i do this ? What do i need to change in the notification definition ?
推荐答案
注册通知
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
}
这篇关于使用CCNotficationCenter传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文