I am working on a project with 20 sprites and I am noticing a lot of code repetition. My sprites are named: sprite1, sprite2, sprite3.... so I am looking for a way to reference a sprite based on 2 variables. The first simply being "sprite" and the second being the integer, so I can change or loop through a range at any time. Is it possible to do something like this? Random example:
x = 1
while x <= 10 {
sprite & x.physicsBody.affectedByGravity = true
x++
}
instead of:
sprite1.physicsBody.affectedByGravity = true
sprite2.physicsBody.affectedByGravity = true
sprite3.physicsBody.affectedByGravity = true
sprite4.physicsBody.affectedByGravity = true
sprite5.physicsBody.affectedByGravity = true
so on...