3

So this may seem like a stupid question; however, I'll see if anyone has an answer.

Is there any way to change the color of all nodes in a scene in swift? For example invert all the colors?

I've created a game using SpriteKit and would like to create different themes. Instead of changing every node one by one. I would like to at least do most in one shot. If anyone has any advice that would be greatly appreciated! Thanks!

-Matt

Matthew Anguelo
  • 293
  • 2
  • 12

1 Answers1

2

Inside of the scene you want,

for node in self.children {
 // I used spritenode, but you can add as many nodes with color options as you like.
  guard let snode = node as? SKSpriteNode else { continue }
  snode.color = .blue
}

The inversion function would be a separate question I think :P but something like:

if snode.color == .black { node.color == .white }

But you could probably do this with RGB and math as well.

Fluidity
  • 3,985
  • 1
  • 13
  • 34