【问题标题】:Pausing a sprite kit scene暂停精灵套件场景
【发布时间】:2014-03-02 19:48:38
【问题描述】:
@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;

除了这里的问题,在我的应用程序委托中

- (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 类型。有任何解决这个问题的方法吗?您是否建议我通过重新键入所有代码将所有场景变成视图?

【问题讨论】:

  • 您似乎对场景和视图感到困惑。您在 skview 上播放您的 skscene。暂停 SKScene 或 SKView 会暂停游戏,但正如 Andrey 建议的那样,这是最好的方法。

标签: ios7 sprite-kit skscene skview


【解决方案1】:

使用SKViewisPaused属性:

斯威夫特

scene.view?.isPaused = true

目标 C

self.scene.view.isPaused = YES;

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

【讨论】:

    【解决方案2】:

    使用场景暂停功能

    self.scene?.view?.paused = true
    

    【讨论】:

      【解决方案3】:

      属性 'paused' 已重命名为 'isPaused'

      scene?.view?.isPaused = true
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-10
        • 2014-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多