Change texture with random

我们两清 提交于 2019-12-24 06:44:06

问题


I have some textures

var texturesOfEnemies = [SKTexture(imageNamed: "EnemyTexture1"),
                         SKTexture(imageNamed: "EnemyTexture2"),
                         SKTexture(imageNamed: "EnemyTexture3"),
                         SKTexture(imageNamed: "EnemyTexture4"),
                         SKTexture(imageNamed: "EnemyTexture5")]

I'm using arc4random to select a random texture

var randomTextureOfEnemies = Int(arc4random_uniform(UInt32(texturesOfEnemies.count)))

and assign the selected texture to a node by

enemy.texture = texturesOfEnemies[randomTextureOfEnemies]

I have some actions for my node. When the actions are done, I want to change the texture of my node.

enemy.run(someAction, completion:{enemy.texture = texturesOfEnemies[randomTextureOfEnemies]})

This actions repeat and are working well, but the textures are only changing once. How can I change the texture every time the action completes?

来源:https://stackoverflow.com/questions/41306264/change-texture-with-random

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!