1
votes

In my AppDelegate's applicationDidEnterBackground() I call cocos2d::Director::getInstance()->stopAnimation() and in applicationWillEnterForeground() I call cocos2d::Director::getInstance()->startAnimation().

But applicationDidEnterBackground can be called with the game still visible on screen, and not only when the game is minimized with the home button (and becomes invisible), for example when you start a buy process in your game, and google billing shows it's popup. If you now rotate the screen with this popup active, the game screen goes all black and the result is a black screen with only the google billing dialog visible. The same happens if the google billing dialog is visible, and you minimize the app and then bring it back.

The only way I can fix this, is by NOT calling stopAnimation.

Does this have a negative impact on battery life, or will cocos2d-x automatically pause all actions while minimized?

The only way I can see how this can be fixed properly, is by knowing whether or not the game is still visible when it's being put in the background, which I could do by overriding the onStop() function on Android.

So how did others solve this? Did you chose to stop the animation and see the black screen as a minor side effect, or do you leave the animation running?

Pause/Resuming the Director has the same effect btw...

Any help would be greatly appreciated!

Kind regards, Mich

1

1 Answers

2
votes

If your game/app enters background mode, its Activity will stop update, so all OpenGL draw calls will be hold no matter you called stopAnimation() or not. So it won't affect battery life if your game doesn't have any background job to do.

Furthermore, why screen goes black when you called stopAnimation()? Let's read some code:

void CCDisplayLinkDirector::mainLoop(void)
{
    if (m_bPurgeDirecotorInNextLoop)
    {
        m_bPurgeDirecotorInNextLoop = false;
        purgeDirector();
    }
    else if (! m_bInvalid)
    {
         drawScene();

         // release the objects
         CCPoolManager::sharedPoolManager()->pop();        
    }
}

void CCDisplayLinkDirector::stopAnimation(void)
{
    m_bInvalid = true;
}

If stopAnimation() was called, it will also stop OpenGL draw call. The last frame of your game will still be shown, but if your game enters background or another Activity or something pops at front, since there's no new draw call updates the game's Activity, it will become whole black.