最好的地方來跟蹤你的對象這樣的球員和其他節點是:
- (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
}
回執
謝謝親愛的@gronzzz作爲回答,我用你的代碼中有,但我仍然有同樣的問題.exactly什麼我想做的事情在YouTube((RubbyBird))遊戲你看將理解我的意思是兄弟,但在我的情況下,玩家在兩個點之間移動,而不是像((rubbyBird))遊戲中的鳥一樣凍結,thanx再次等待您的答案 – Amory 2014-12-04 17:43:46
好吧,我理解您的問題,更新我的帖子 – gronzzz 2014-12-04 18:04:25
Guys I仍然有同樣的問題。讓我更清楚地說(讓我說我想讓我的SKNode「玩家」在兩點之間滑動通過觸摸,你必須保持滑動,如果你停止滑動遊戲將結束)...感謝求助 – Amory 2014-12-05 10:11:58