I am trying to build a simple obstacle jumping app. I want the image for the obstacle to be picked randomly from a set of images. I have tried using a combination of the arc4random_uniform function and switch case but that doesn't seem to update the SKSpriteNode. What am i doing wrong?
class PlayScene: SKScene, SKPhysicsContactDelegate{
...
var block3 = SKSpriteNode(imageNamed: "lion")
....
}
override func update(currentTime: NSTimeInterval) {
.....
blockRunner()
}
func blockRunner() {
var imageNamedAnimal = ""
var randomIndex = arc4random_uniform(2)
switch(randomIndex) {
case 0 : imageNamedAnimal = "turtle"
case 1: imageNamedAnimal = "lion"
default: imageNamedAnimal = "turtle"
}
block3 = SKSpriteNode(imageNamed: imageNamedAnimal)
.....
}
At what point should i try to set the random image? Block3 seems to pick the lion image always which i had sent at the beginning of the code despite the fact that imageNamedAnimal shows random values in each frame.