Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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‎

Lines changed: 12 additions & 2 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /