如果玩家移动停止,如何重新开始游戏

时间:2014-12-04 11:29:13

标签: objective-c sprite-kit

我期待创造一个游戏,在游戏场景中,我让我的SKNode称为“玩家”,玩家通过触摸移动,我需要做的是:如果你停止了“玩家”,我怎么能让你失去游戏运动,保持“玩家”移动,我使用触摸结束的方法,但它不是我需要的 如果您看过rubby bird游戏,您可以了解我需要什么。我的意思在所有这一切,如果玩家速度= 0然后重新开始游戏。并且运动的玩家速度是player.sped = 3;

  

-(void)didBeginContact:(SKPhysicsContact *)contact{ player.speed = 0 } ...

任何建议都会有所帮助。 感谢

1 个答案:

答案 0 :(得分:0)

跟踪玩家和其他节点等对象的最佳位置是:

- (void)update:(CFTimeInterval)currentTime;

在这里,您可以检查您的玩家是否加速不变。如果速度改变则显示新场景。这是伪代码

    - (void)update:(CFTimeInterval)currentTime
    {
        // check player collisions
        // after that check players speed  
        if (player.speed <= 0)
        {
           // show another scene and restart the game
           EndScene *scene = [EndScene sceneWithSize:viewSize];

          // draw label
          SKLabelNode *myLabel = [SKLabelNode labelNodeWithFontNamed:@"Arial"];
          myLabel.text = @"Game Over";
          myLabel.fontSize = 20;
          myLabel.position = CGPointMake(CGRectGetMidX(self.frame),         CGRectGetMidY(self.frame));
          [scene addChild:myLabel];

          [self presentScene: scene];
        }
        // else if speed is still > 0 and game continuing, so nothing to do
    }

修改的 我理解你的问题,所以有很多方法可以做到: 1)你可以使用你的触摸方法并且总是保存用户的手指位置,所以如果下次调用这个方法的位置没有改变正确的方向,那么他输了; 2)你可以升级我的“更新”方法,以获得玩家触摸位置之间的差异。

- (void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */
    // Handle time delta.
    // If we drop below 60fps, we still want everything to move the same distance.
    CFTimeInterval timeSinceLast = currentTime - self.lastUpdateTimeInterval;
    self.lastUpdateTimeInterval = currentTime;
    if (timeSinceLast > kMinTimeInterval) { // more than a second since last update
        timeSinceLast = kMinTimeInterval;
        self.lastUpdateTimeInterval = currentTime;
        self.worldMovedForUpdate = YES;
    }

    [self updateWithTimeSinceLastUpdate:timeSinceLast];
}

- (void)updateWithTimeSinceLastUpdate:(NSTimeInterval)timeSinceLast
{
    // here you get timeSinceLast update loop, so here you know touch position from last iteration and touch position from current iteration
}

让我发布

相关问题