dimanche 12 juillet 2015

How to randomly choose a SKSpriteNode?

I want to choose from 4 enemies sing random and present it on scene. For that purpose I've made this:

func enemyPicker() -> SKSpriteNode {
    var enemyArray = [mouse, robot, drone, block, bird]
    var countArray = UInt32(enemyArray.count)
    var pickOneEneny = arc4random_uniform(countArray)
    var randomElement = Int(pickOneEnemy)

    return enemyArray.randomElement
}

But Xcode says to me that SKSpriteNode does not have a member named randomElement. And it surely doesn't, but how would I say to my function that I need it to pick and assign that random Int to an actual enemy from array?

I tried to use this answer but it's not working for me. I also tried to change -> SKSpriteNode to SKTexture, String and "T" and had not any luck with it.




Aucun commentaire:

Enregistrer un commentaire