How To Create Array Of SKSpriteNodes? (swift, spritekit)

泄露秘密 提交于 2019-12-08 12:37:44

问题


I have 12 ball sprites all of which have the same attributes. Is it possible to put them all in an array so I dont have to keep typing....

      ball1.size.......
      ball2.size........
      ball3.size......

Etc.

I would like to create an array called allBalls and then just change every ball through one line of code like shown...

      allBalls.size.....

回答1:


To create an array of SKSpriteNodes you could do the following:

let allBalls = [ball1, ball2, ball3] // Of type Array<SKSpriteNode>

Then iterate through the array and change the size property of each ball:

for ball in allBalls {
    ball.size = // Whatever size you want.
}


来源:https://stackoverflow.com/questions/29879848/how-to-create-array-of-skspritenodes-swift-spritekit

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