I have multiple sprites with diffrent names, like "H1", "H2", "H3" and so on, how do I code so that all sprites with the name "H2" change their color to red?
Asked
Active
Viewed 329 times
3
-
Does this answer your question? [SpriteKit: find all descendants of SKNode of certain class?](https://stackoverflow.com/questions/44274220/spritekit-find-all-descendants-of-sknode-of-certain-class) – Maetschl Jul 17 '20 at 11:51
1 Answers
2
One way would be to create an array of all you sprites, then do something like this.
var spriteArray: [sprite] = [sprite1, sprite2, sprite3, sprite4]
for sprite in spriteArray where (sprite.name == "H2" {
sprite.color = UIColor.red
}

Zbud68
- 119
- 10
-
1Thank you! I also figured out that you dont need an array just: for nodes in self.children{if node.name == "sprite", node.removefromparent} – Artur D Aug 02 '20 at 08:57