Scene pause difficulties

I’m having difficulties pausing the scene on user fail.

auto failFunc = CallFunc::create([](){
             Director::sharedDirector()->pause();
});

auto failScene = CallFunc::create([](){
             Director::sharedDirector()->resume();
             auto scene = GameOverScene::createScene();
     Director::getInstance()->replaceScene(TransitionFade::create(TRANSITION_TIME, scene));
});

auto SeqFail = Sequence::create(failFunc, DelayTime::create(1), failScene, nullptr);

this->runAction(SeqFail);

The scene pauses well, but does not resume. Any ideas?

When you pause the director it no longer processes Actions. You’ll want to either pause the children of your scene, or unschedule their update methods, or if you have one main run loop then just check if paused, or something along those lines.

You could also not use an action here and just create a 1+ second transition with fade and then your current scene will just unload prior to the new scene loading.

So you say that Director::getInstance()->getRunningScene()->pause(); & Director::getInstance()->getRunningScene()->resume(); will do it, don’t you? I tried that and unfortunately i miss something i guess.

You don’t want to pause the node that you are trying to run an action on. So you don’t want to pause the scene if you are running the action on the scene. Pausing the director halts everything.

Depending on whether you use scheduleUpdate or actions or both you will probably have to pause all nodes that are children your scene, recursively, then run the action on your scene.

Other similar discussions:

// pause nodes
void Game::pauseNodeAndDescendants(Node *pNode)
{
    pNode->pauseSchedulerAndActions();
    for(const auto &child : pNode->getChildren())
    {
        this->pauseNodeAndDescendants(child);
    }
}
// resume nodes
void Game::resumeNodeAndDescendants(Node *pNode)
{
    pNode->resumeSchedulerAndActions();
    for(const auto &child : pNode->getChildren())
    {
        this->resumeNodeAndDescendants(child);
    }
}
1 Like