cocos2d游戏中如何实现暂停/恢复?

How to implement pause/resume in cocos2d game?(cocos2d游戏中如何实现暂停/恢复?)

本文介绍了cocos2d游戏中如何实现暂停/恢复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是寻找 cocos2d 游戏期间暂停/恢复状态(包括所有需要保存的数据信息)的设计解决方案.

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).用户选择退出,然后弹出一个对话框供用户选择直接退出"、暂停";

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

2).有人呼入,弹出对话框供用户选择退出"或暂停"游戏.

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

如果选择暂停",应该保存所有值得保存的内容.就像 PC 游戏一样.

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 ?

感谢任何线索或评论.

欢迎通过电子邮件进一步讨论:apple.dev.sh@gmail.com

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

推荐答案

这是一个很好的例子:

暂停:

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

恢复时:

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

这篇关于cocos2d游戏中如何实现暂停/恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:cocos2d游戏中如何实现暂停/恢复?

基础教程推荐