Lio*_*lak 14 background ios7 sprite-kit
我试图在代码中的任何地方进行搜索:解释文档在进入后台时它的作用,或者它是否在某个时候暂停,但是无济于事 - 有人指导我在进入后台时的建议方式精灵套件启用游戏?
我应该打电话scene.paused = YES,或者如何确认背景中没有画图,这样我可以避免iOS终止,这不允许我这样做?
谢谢!
Mas*_*uin 39
SpriteKit实际上还没有记录,可能是因为它太新了,相对较少的开发人员已经实现了它.SpriteKit 应该在后台运行时暂停动画,但根据我的经验(和harrym17),它将导致内存访问错误并完全退出应用程序而不是后台处理.
根据Apple开发者论坛的说法,这似乎是SpriteKit中的一个已知错误(根据harrym17的评论,它并不总是在后台时停止动画,因为它应该)导致内存访问错误.这是一个简单的解决方案,对我有用 - 我的应用程序在后台时一直崩溃,并且因为添加此代码一切正常.
(感谢Keith Murray在Apple论坛上提供此代码;据我所知,他没有在SO上发布它).
在AppDelegate.h,请确保您导入SpriteKit:
#import <SpriteKit/SpriteKit.h>
Run Code Online (Sandbox Code Playgroud)
在AppDelegate.m,编辑您的applicationWillResignActive方法:
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
// pause sprite kit
SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = YES;
}
Run Code Online (Sandbox Code Playgroud)
这对你的applicationDidBecomeActive方法:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
// resume sprite kit
SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = NO;
}
Run Code Online (Sandbox Code Playgroud)
AVAudioSession显然,当播放音频时背景化还有其他问题; 此线程中提到了一种解决方法.
Lio*_*lak 14
至于说这里的LearnCocos2D:
问题是AVAudioSession在应用程序进入后台时无法激活.
修复非常简单,也适用于ObjectAL =>在应用程序处于后台时将AVAudioSession设置为非活动状态,并在应用程序进入前台时重新激活音频会话.
使用此修复程序的简化AppDelegate如下所示:
#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];
}
Run Code Online (Sandbox Code Playgroud)
PS:此修复程序将包含在Kobold Kit v7.0.3中.
小智 10
我想知道为什么在世界上这个看似简单的解决方案导致我在应用启动时崩溃,但这是因为我有iAd运行.因此,要记住一件事:@ MassivePenguin的答案有效,但如果你有iAd,你将不得不抓住SKView通过subviews或它(显然)崩溃.
-(SKView*)getSKViewSubview{
for (UIView* s in self.window.rootViewController.view.subviews) {
if ([s isKindOfClass:[SKView class]]) {
return (SKView*)s;
}
}
return nil;
}
- (void)applicationWillResignActive:(UIApplication *)application {
SKView* view = [self getSKViewSubview];
if (view) {
view.paused = YES;
}
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
SKView* view = [self getSKViewSubview];
if (view) {
view.paused = NO;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10146 次 |
| 最近记录: |