How to implement pause/resume in cocos2d game?

后端 未结 1 667
被撕碎了的回忆
被撕碎了的回忆 2021-01-31 23:47

My question is to look for design solution for pause/resume states (including all data info, which need save ) during cocos2d game.

Including following cases, but not li

1条回答
  •  臣服心动
    2021-02-01 00:22

    Here is a good example:

    To pause:

    - (void) applicationDidEnterBackground:(UIApplication *)application
    {
        [[CCDirector sharedDirector] stopAnimation];
        [[CCDirector sharedDirector] pause];
    }
    - (void)applicationWillResignActive:(UIApplication *)application
    {
        [[CCDirector sharedDirector] stopAnimation];
        [[CCDirector sharedDirector] pause];
    }
    

    When resuming:

    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        [[CCDirector sharedDirector] stopAnimation]; // call this to make sure you don't start a second display link!
        [[CCDirector sharedDirector] resume];
        [[CCDirector sharedDirector] startAnimation];
    }
    

    0 讨论(0)
提交回复
热议问题