SpriteKit-正确的方式进行多任务处理 [英] SpriteKit- the right way to multitask

查看:122
本文介绍了SpriteKit-正确的方式进行多任务处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在code到处搜索:解释去图书文献时的背景,或者如果它甚至暂停一段时间,但没有可用它做什么有人可以告诉我在什么建议的方式在精灵套件使游戏去后台时怎么办?

我是否应该打电话 scene.paused = YES ,不然我怎么能确认没有图纸发生在后台,所以我可以通过iOS的避免终止,不会让我呢?

谢谢!


解决方案

作为说<一href=\"http://stackoverflow.com/questions/18976813/sprite-kit-playing-sound-leads-to-app-termination/19283721\"标题=点击这里>按这里 LearnCocos2D


  而应用程序进入后台

问题是AVAudioSession不能活动。


  
  

解决方法是相当简单,而且也适用于ObjectAL =>设置AVAudioSession为无效,而应用程序是在后台,当应用程序进入前景激活音频会话。


  
  

此修复程序简化的AppDelegate看起来像这样:


 #进口&LT; AVFoundation / AVFoundation.h&GT;... - (无效)applicationWillResignActive:(UIApplication的*)的应用
{
    // prevent音频崩溃
    [AVAudioSession sharedInstance] SETACTIVE:没有错误:无];
} - (无效)applicationDidEnterBackground:(UIApplication的*)的应用
{
    // prevent音频崩溃
    [AVAudioSession sharedInstance] SETACTIVE:没有错误:无];
} - (无效)applicationWillEnterForeground:(UIApplication的*)的应用
{
    //恢复音频
    [AVAudioSession sharedInstance] SETACTIVE:YES错误:无];
}


  

PS:此修复程序将包含在狗头包v7.0.3


I tried to search everywhere in the code:Explained documentry what it does when going to background, or if it is even paused sometime, but to no avail- can someone direct me in the way of what is recommended to do when going to background in sprite kit enabled game?

Should I just call scene.paused = YES, or how can I confirm that no drawing occurs in background so I can avoid termination by iOS which won't allow me that?

Thanks!

解决方案

As said here by LearnCocos2D:

The problem is AVAudioSession can't be active while the app enters background.

The fix is quite simple, and also applies to ObjectAL => set the AVAudioSession to inactive while the app is in background, and reactivate the audio session when the app enters foreground.

A simplified AppDelegate with this fix looks like so:

#import <AVFoundation/AVFoundation.h>

...

- (void)applicationWillResignActive:(UIApplication *)application
{
    // prevent audio crash
    [[AVAudioSession sharedInstance] setActive:NO error:nil];
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // prevent audio crash
    [[AVAudioSession sharedInstance] setActive:NO error:nil];
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // resume audio
    [[AVAudioSession sharedInstance] setActive:YES error:nil];
}

PS: this fix will be included in Kobold Kit v7.0.3.

这篇关于SpriteKit-正确的方式进行多任务处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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