File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments