简体   繁体   中英

How to implement pause/resume in cocos2d game?

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 limited:

1). User choose quit, then pop out one dialog for user to choose " quit directly", " pause " ;

2). Someone call in , pop out dialog for user to choose "quit " or " pause " game.

If choose "pause", everything which deserve saving, should be saved. Just like PC games do.

I know Director provides "pause" , "resume " , is that okay for this task ?

Thanks for anyone clues or comments.

Welcome for further discussing via email : apple.dev.sh@gmail.com

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];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM