samedi 26 décembre 2015

Cocos2d callback function

I am brand new to cocos2d programming and although I have programmed in C++ (17+ years ago) a lot has changed and I am struggling with the basics.

I have a function in gamescene which I want to pause the game, create a PauseScene instance and

void GameScene::pauseButtonCallback() {
    Director::getInstance()->pause();

    auto callbackResume = CallFunc::create([=](){
        GameScene::resumeGame();
    });

    auto pauseScene = PauseScene::createSceneWithCloseCallback(callbackResume);

    this->addChild(pauseScene, 5);
}

PauseScene.h

Scene* createSceneWithCloseCallback(CallFunc *callback);

Unfortunately I am getting an error on the line where I call PauseScene::createSceneWthCloseCallback(callbackResume) in the form of:

"call to non-static member function without an object argument?"

The idea here is I would set a callback block when instantiating the PauseScene which later gets invoked when the player hits the resume button.

Also I know that PauseScene is a child of GameScene and I can take a shortcut and just do parent->function() but I would like to accomplish this with callback blocks.

Any help would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire