Is there a way to invert the colors of a SKSpriteNode

萝らか妹 提交于 2019-12-06 04:21:42

问题


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


回答1:


You can invert the colors by applying a CIFilter with an 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 an SKScene is an effect node, so this makes inverting an entire scene very easy:

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


来源:https://stackoverflow.com/questions/28652839/is-there-a-way-to-invert-the-colors-of-a-skspritenode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!