簡體   English   中英

在iOS8中使用appdelegate暫停Spritekit游戲

[英]pausing spritekit game using appdelegate in ios8

我的游戲中有一個暫停菜單,當我按下主屏幕按鈕時,我想切換該菜單。 當我進入游戲時它可以工作,但是當我按下主頁按鈕時,菜單會出現,但游戲不會暫停。

當我重新啟動應用程序時,菜單仍然存在,但是游戲會自行取消暫停。 當您離開並進入應用程序時,spritekit似乎自動自動暫停並重新啟動游戲。 當我進入應用程序時,我就可以完全控制它。 但是,當我退出/進入應用程序時,它會表現出它喜歡的樣子。

有什么建議么?

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

發送NSNotificationGameSceneViewController以暫停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;
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM