Change the color of all nodes in the scene?
So this may seem like a silly question; however, I'll see if anyone has an answer.
Is there a way to change the color of all nodes in the scene in swift? For example, invert all colors?
I have created a game with SpriteKit and would like to create different themes. Instead of changing every node one by one. I would like to at least do everything in one shot. If anyone has any advice that would be greatly appreciated! Thank!
Matt
+3
source to share
1 answer
Inside 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 will be a separate question, which I think: P, but something like:
if snode.color == .black { node.color == .white }
But you could probably do it with RGB and math.
+2
source to share