在 ios8 中使用 appdelegate 暂停 spritekit 游戏 [英] pausing spritekit game using appdelegate in ios8
问题描述
我的游戏中有一个暂停菜单,当我按下主页按钮时,我想切换该菜单.当我在我的游戏中时它可以工作,但是当我按下主页按钮时菜单出现,但游戏不会暂停.
当我重新启动应用程序时,菜单仍然存在,但游戏自行取消暂停.当您离开并进入应用程序时,似乎 spritekit 会自动暂停并自行重新启动游戏.当我在应用程序中时,我可以完全控制它.但是当我退出/进入应用程序时,它的行为就像它喜欢的那样.
有什么建议吗?
func applicationWillResignActive(application: UIApplication!) {//获取根视图控制器//切换我的暂停菜单方法.暂停菜单集 skview.paused = true}
发送一个 NSNotification
到 GameSceneViewController
来暂停 SKScene
:>
应用程序委托:
- (void)applicationWillResignActive:(UIApplication *)application{//暂停精灵套件场景[[NSNotificationCenter defaultCenter] postNotificationName:@"PauseGameScene" object:self];}
GameSceneViewController:
- (void)viewDidLoad {[[NSNotificationCenter defaultCenter] addObserver:self选择器:@选择器(暂停游戏场景)名称:@"PauseGameScene"对象:无];}- (void)pauseGameScene {如果(self.skView.scene){self.skView.paused = self.skView.scene.paused = YES;}}
I have a pause menu in my game that I want to toggle when the i hit my home button. it works when I'm within my game, however when I hit my home button the menu comes up, but the game will not pause.
when i restart the app, the menu is still there, but the game un-pauses itself. It seems like spritekit automatically pauses and restarts the game on its own when you leave and enter the app. When I'm within the app I have full control over it. But when I'm exiting/entering the app it behaves how it likes.
Any suggestions?
func applicationWillResignActive(application: UIApplication!) {
// get the root viewcontroller
// toggle my pausemenu method. pause menu sets skview.paused = true
}
Send an NSNotification
to GameSceneViewController
to pause the SKScene
:
AppDelegate:
- (void)applicationWillResignActive:(UIApplication *)application
{
// Pause sprite kit scene
[[NSNotificationCenter defaultCenter] postNotificationName:@"PauseGameScene" object:self];
}
GameSceneViewController:
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(pauseGameScene)
name:@"PauseGameScene"
object:nil];
}
- (void)pauseGameScene {
if (self.skView.scene) {
self.skView.paused = self.skView.scene.paused = YES;
}
}
这篇关于在 ios8 中使用 appdelegate 暂停 spritekit 游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!