I don't know why this error appears in the code:
func torpedoDidCollideWithAlien(torpedo:SKSpriteNode, alien:SKSpriteNode){
print("HIT")
torpedo.removeFromParent()
alien.removeFromParent()
var aliensDestroyed = 0
aliensDestroyed += 1
if (aliensDestroyed > 10){ //Transition to GameOver or Success
let transition:SKTransition = SKTransition.flipHorizontalWithDuration(0.5)
let gameOverScene:SKScene = GameOverScene(size: self.size, won: true)
self.view?.presentScene(gameOverScene, transition: transition)
}
The error is at the line:
let transition:SKTransition = SKTransition.flipHorizontalWithDuration(0.5) //'Will never be executed'
You declare a new variable named
aliensDestroyedwith a value of0. You then increment the value to1.You then check to see if the value is greater than 10. That can't ever be true. It will always be
1.Therefore the contents of the
ifstatement will never execute.What you probably want is an instance variable named
aliensDestroyedinstead of creating a new local variable inside yourtorpedoDidCollideWithAlienfunction.