How to implement pause/resume in cocos2d game?(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游戏中如何实现暂停/恢复?
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01