i have 5 skspritesnodes, i want to spawn 1 random node at a time, i know i have to use arc4random but the examples ive tried dont seem to work. Id like a variable i can then input where ever i need start spawning random looking "enemys"
var bird0 = SKSpriteNode(imageNamed: "back_bird")
var bird1 = SKSpriteNode(imageNamed: "blue_bird")
var bird2 = SKSpriteNode(imageNamed: "green_bird")
var bird3 = SKSpriteNode(imageNamed: "purple_bird")
var bird4 = SKSpriteNode(imageNamed: "orange_bird")
i have the physicsbody set for each, size, ect. everything is all set minus the ability to randomly pick one to come out
You need to put the sprites in an array. Then, you can access a random element in that array.
Here's a function that returns a random bird.
You can also, put all the birds in an array and remove the variables
bird0
,bird1
,bird2
and so on:Then
birds[Int(arc4random_uniform(UInt32(array.count)))]
will get you a random bird.