How do I get a Node by its name in SpriteKit?

Viewed 166

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?

1 Answers

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
}
Related