jeudi 19 avril 2018

else if condition not executing statement

I am building a gameOver scene where if you reach a certain amount of Points you either get 1, 2 or 3 Stars.

I wrote a if Condition block that looks like this:

var starImage = SKSpriteNode()
    if gameScore > 500 {
        starImage = SKSpriteNode(imageNamed: "2_stars")
        print("You achieved 2 Stars")
    } else if gameScore > 1000 {
        starImage = SKSpriteNode(imageNamed: "3_stars")
        print("You achieved 3 Stars")
    } else {
        starImage = SKSpriteNode(imageNamed: "1_star")
        print("You achieved 1 Star")
    }
    starImage.setScale(2)
    starImage.position = CGPoint(x: self.size.width / 2, y: self.size.height * 0.9)
    starImage.zPosition = 2
    self.addChild(starImage)

2_stars and 1_star work fine, but the else if condition doesn't seem to execute.

However the weird thing is, when I replace the greater than (>) symbols with equals (==) all 3 conditions work.

I did try using >= but that has the same effect as >.

Anyone know why this is happening?

Aucun commentaire:

Enregistrer un commentaire