Skip to content

Commit 6bc5c4f

Browse files
author
Guled
committed
Fixed Flappy Bird Bug
1 parent e8cafb7 commit 6bc5c4f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Example/MLKit/GameScene.swift

+12-2
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,21 @@ class GameScene: SKScene, SKPhysicsContactDelegate {
460460

461461
// Check to see if the pipe in front has gone behind the bird
462462
// if so, make the new pipe in front of the bird the target pipe
463-
if pipes.children[currentPipe].position.x < bird.position.x {
463+
if pipes.children.count > 1 {
464+
if pipes.children[currentPipe].position.x < bird.position.x {
464465

465-
currentPipe = closestPipe(pipes: pipes.children)
466+
currentPipe = closestPipe(pipes: pipes.children)
467+
}
468+
}
469+
470+
if pipes.children.count == 1 {
471+
if pipes.children[0].position.x < bird.position.x {
472+
473+
currentPipe = 0
474+
}
466475
}
467476

477+
468478
// Distance between next pipe and bird
469479
let distanceOfNextPipe = abs(pipes.children[currentPipe].position.x - bird.position.x)
470480

0 commit comments

Comments
 (0)