C++ 通过CCNotificationCenter传递数据

C++ 通过CCNotificationCenter传递数据,c++,cocos2d-x,C++,Cocos2d X,我是Cocos2d-X的新手 CCNotificationCenter::sharedNotificationCenter()->addObserver( this, callfuncO_selector(test::printSomething), "hello", NULL); 回调函数是 void PingoScreen::printSomething(CCObject *pObject

我是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);
删除通知

CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(GameScene::doSomething), "eventNotification", NULL);
CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, "eventNotification");
CCNotificationCenter::sharedNotificationCenter()->postNotification("eventNotification", myString);
发布通知

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
}

寄存器通知代码中最后一个NULL表示什么?addObserver中的额外对象参数用作过滤器。如果设置为对象,则只有此发件人发送的通知才会传递给观察者。如果设置为NULL,则此类型的所有通知都将传递给观察者。