I am using cocos2d-x 3.2.
Is there any way to display a “paused game” menu BEFORE entering the background? What I would like my game to do is this:
- game is about to enter the background (either due to user manually sending the game to the background, receiving a phone call, etc), so a “pause menu” is displayed. Animation and music is stopped.
- game enters background
- game moves back to foreground and the user sees the “pause menu”.
- user presses the “resume” button and animation and music resumes
I have the following code currently:
void AppDelegate::applicationDidEnterBackground() {
//SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
Scene* scene = Director::getInstance()->getRunningScene();
GameLayer* gameLayer = scene->getChildByName<GameLayer*>("GameLayer");
if (gameLayer != 0)
{
gameLayer->pauseGame();
}
Director::getInstance()->stopAnimation();
}
The pauseGame()
function is responsible for displaying the pause game menu. The problem I am facing is that the game enters the background before the next update loop occurs, which means the pause game menu is not actually displayed until the game enters the foreground (this only happens if I call Director::getInstance()->startAnimation()
in applicaitonWillEnterForeground
). If startAnimation()
is never called in applicationWillEnterForeground()
, then the pause game menu never displays at all. Is there any way to get around this? I would like for the callback function of pressing the “resume game” button to resume the game animation and music. Thanks for any info!