问题
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 SKSpriteNode
s 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