ios7 - 暂停 Sprite 套件场景

标签 ios7 sprite-kit skscene skview

@property (SK_NONATOMIC_IOSONLY, getter = isPaused) BOOL paused;

我发现这行代码可以添加到我的项目中,我将如何暂停整个游戏?

例如:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
for (UITouch *touch in touches)
{
    SKSpriteNode *pause = (SKSpriteNode*)[self childNodeWithName:@"pause"];
    CGPoint location = [touch locationInNode:self];
    // NSLog(@"** TOUCH LOCATION ** \nx: %f / y: %f", location.x, location.y);

    if([pause containsPoint:location])
    {
        NSLog(@"PAUSE GAME HERE SOMEHOW");
    }
}

}

如您所见,我已经设置了按钮。当我选择它时,我将如何暂停整个场景?然后当有人点击恢复按钮时恢复它。

好的,所以我有一些建议可以打电话
  self.scene.view.paused = YES;

除了这是问题,在我的应用程序委托(delegate)中
- (void)applicationWillResignActive:(UIApplication *)application{


SKView *view = (SKView *)self.window.rootViewController.view;
view.paused = YES;}


- (void)applicationDidBecomeActive:(UIApplication *)application{

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

当它实际上是 SKScene 时,我将其设为 SKView 类型。有任何解决这个问题的方法吗?您是否建议我通过重新输入所有代码将所有场景变成 View ?

最佳答案

使用SKView isPaused 属性(property):

swift :

scene.view?.isPaused = true

objective-c :
self.scene.view.isPaused = YES;

这将停止所有 Action 和物理模拟。

关于ios7 - 暂停 Sprite 套件场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21593198/

相关文章:

swift - Spritekit : Change a scene and keep the background

swift - 如何在 SKScene 中使用另一个变量初始化一个变量

ios - SpriteKit SKScene 中的相机属性始终为 nil

ios - 关闭 ViewController 后,我的 View 保持在 iOS 7 中以前的 View Controller 方向

xcode4 - iOS7/XCode5 - 立即调用 "viewDidLoad",而不是在调用 "presentViewController"时调用

iOS:减少应用程序进入前台时 UIAlertView 显示的延迟

swift - 将 SKSpriteNode 旋转到另一个 SKSpriteNode

ios - 在ios标签栏中禁用编辑按钮

ios - Spritekit 运动轨迹

swift - 根据节点的旋转对节点施加力