SceneKit - 进入非活动模式会导致“SCNAction”故障

问题描述 投票:1回答:1

我目前正在开发一个SceneKit应用程序,我最近在我的iPhone 5s上测试时遇到了问题。

我写下面的代码反复左右移动块,一切正常。

SCNAction *mn1 = [SCNAction moveByX:-2.2 y:0 z:0 duration:1];
SCNAction *mn2 = [SCNAction moveByX:2.2 y:0 z:0 duration:1];
SCNAction *mn3 = [SCNAction waitForDuration:0.5];
SCNAction *mns = [SCNAction repeatActionForever:[SCNAction sequence:@[mn3,mn1,mn3,mn2]]];
[self.blueNode1 runAction:mns];

并在AppDelegate.m中

- (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.

SCNView *view = (SCNView *)self.window.rootViewController.view;
view.scene.paused = YES;

}

- (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.

SCNView *view = (SCNView *)self.window.rootViewController.view;
view.scene.paused = NO;

}

当我通过主页按钮进入“后台/非活动模式”并返回我的应用程序时,一切仍然顺利进行。

当我通过电源按钮进入“背景”并等待几秒钟后返回我的应用程序。 blueNode1将以非常快的速度重复运行一段时间。当我返回应用程序时,我花掉应用程序的时间越长,块以极快的速度移动。我不确定为什么会这样,但它可能是一个破坏游戏的错误。

我希望我能清楚地解决问题。任何帮助表示赞赏。

编辑:我刚刚创建了一个全新的测试应用程序,看看我是否可以重新创建一个新项目的错误,我能够。当我的iPhone通过我的Mac运行应用程序时似乎没有发生,但是,一旦我拔掉我的iPhone并通过它运行测试应用程序,我就能够在新项目上重新创建它。

background action repeat scenekit pausing-execution
1个回答
0
投票

尝试在SCNScene上使用暂停属性

https://developer.apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SCNScene_Class/index.html#//apple_ref/occ/instp/SCNScene/paused

它实际上对SCNActions有影响,不像SCNView上的pause()/ play()方法。

如果你不能使用它我会建议尝试更改所有SCNActions上的速度属性,但我没有尝试过。

© www.soinside.com 2019 - 2024. All rights reserved.