在ios8中使用appdelegate暂停spritekit游戏 [英] pausing spritekit game using appdelegate in ios8

查看:126
本文介绍了在ios8中使用appdelegate暂停spritekit游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的游戏中有一个暂停菜单,当我按下我的主页按钮时,我想要切换。当我在我的游戏中时,它会起作用,但是当我按下我的主页按钮时,菜单会出现,但游戏不会暂停。

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.

当我重新启动应用程序时,菜单仍然存在,但游戏不会停顿。当您离开并进入应用程序时,似乎spritekit会自动暂停并重新启动游戏。当我在应用程序内时,我可以完全控制它。但是当我退出/进入应用程序时,它表现得如何。

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.

有什么建议吗?

func applicationWillResignActive(application: UIApplication!) {
    // get the root viewcontroller
    // toggle my pausemenu method.  pause menu sets skview.paused = true
}


推荐答案

发送 NSNotification GameSceneViewController 暂停 SKScene

AppDelegate:

AppDelegate:

- (void)applicationWillResignActive:(UIApplication *)application
{    
    // Pause sprite kit scene
    [[NSNotificationCenter defaultCenter] postNotificationName:@"PauseGameScene" object:self];
}

GameSceneViewController:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆