Is there any way to invert SKSpriteNode colors

I was wondering if it is possible to invert the colors (or adjust the hue) of SKSpriteNode.

+4
source share
1 answer

You can invert colors using CIFilter with SKEffect node. Something like this should work:

SKEffectNode *effectNode = [[SKEffectNode alloc] init];
effectNode.filter = [CIFilter filterWithName:@"CIColorInvert"];

SKSpriteNode *node = yourNode; // Make sure this node doesn't already have a parent
[effectNode addChild:node];
[self addChild:effectNode];

Note that this SKSceneis a node effect, so it greatly simplifies the inversion of the entire scene:

// self is a scene here
self.filter = [CIFilter filterWithName:@"CIColorInvert"];
self.shouldEnableEffects = YES;
+2
source

All Articles