How to implement pause/resume in cocos2d game?

守給你的承諾、 提交于 2019-12-03 04:38:40

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/3082718/how-to-implement-pause-resume-in-cocos2d-game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!