gpt4 book ai didi

c++ - 使用 CCNotficationCenter 传递数据

转载 作者:行者123 更新时间:2023-11-28 07:13:57 25 4
gpt4 key购买 nike

我是 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++ - 使用 CCNotficationCenter 传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20537329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com