我是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
}

08-18 01:39