We never had this issue with Cocos2d-x 1.x, but now have an issue with Cocos2d-x 2.x.
I have an app that is animating (drawing a lot to the screen each frame) and when I minimize my app by pressing the home button, then try to resume the app, I am brought back to the correct place, but the animations have stopped and even though I can “play” the game, I never see anything change. It is as if the game is active beneath a snapshot of where I was before I suspended my app. Sounds, buttons, navigation, etc are all functional, but all I see is the last frame before I suspended the app.
I assume this must be a bug introduced in the 2.0.x versions of Cocos2d-x.
Just to make sure I am handling the suspend/resume properly, here is my code in AppDelegate.cpp:
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
CCDirector::sharedDirector()->stopAnimation();
CCDirector::sharedDirector()->pause();
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->stopAnimation(); // To ensure we aren't already started
CCDirector::sharedDirector()->resume();
CCDirector::sharedDirector()->startAnimation();
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
One more thing. This does not happen every time you suspend/resume. It only happens occasionally.
It’s almost like the draw() code is on it’s own thread and occasionally when you resume it still performs all of the game logic, but doesn’t resume the drawing thread. Of course I am just guessing, for all I know there isn’t a separate draw thread.