Cocos2DXNA / cocos2d-xna

XNA Port of Cocos2d-X
www.cocos2dxna.com
226 stars 123 forks source link

Resume calls OnEnter but not balanced with OnExit #273

Open totallyeviljake opened 11 years ago

totallyeviljake commented 11 years ago

When the game pauses, the current scene and its children do not receive an OnExit call. Yet, when the game resumes, the scene graph receives an OnEnter call. This causes an imbalance in any state that may change during OnEnter that would otherwise be balanced by OnExit.

totallyeviljake commented 11 years ago

This may be a phenomenon of MonoGame.

totallyeviljake commented 11 years ago

This also happens on WP7. Open the game, click the windows button, note the onExit is not called. Resume the game (back button), note OnEnter is called.

totallyeviljake commented 11 years ago

The problem is from using CCDirector.ResumeFromBackground() which calls onEnter on the top scene when it is not a transition scene.

totallyeviljake commented 11 years ago

As you can see, the pause() method does not call OnExit, but the ResumeFromBackground does call OnEnter

    public void Pause()
    {
        if (m_bPaused)
        {
            return;
        }

        m_dOldAnimationInterval = m_dAnimationInterval;

        // when paused, don't consume CPU
        AnimationInterval = 1 / 4.0;
        m_bPaused = true;
    }

    public void ResumeFromBackground()
    {
        Resume();

        if (m_pRunningScene != null)
        {
            bool runningIsTransition = m_pRunningScene is CCTransitionScene;
            if (!runningIsTransition)
            {
                m_pRunningScene.OnEnter();
                m_pRunningScene.OnEnterTransitionDidFinish();
            }
        }
    }
gena-m commented 11 years ago

Pause () terminates the call is shedule Update () only

gena-m commented 11 years ago

Need a pair call, for example EnterToBackground, that would make a pause, and caused OnExit

gena-m commented 11 years ago

the latest version of cocos2d-x is not ResumeFromBackground in CCDirector. but has ApplicationProtocol: applicationDidEnterBackground and applicationWillEnterForeground

totallyeviljake commented 11 years ago

ResumeFromBackground was added by me. It needs a balancing method, or to be removed. I forget why I added it and did not document why it was added.