Reputation: 797
I'm trying to create a background for my game with a gradient, directly into SpriteKit. I've tried several things but nothing works and I haven't found any helping advice. The first thing: I'm creating a background SKSpriteNode
with a color, then I'm doing the following, which does not appear.
CIFilter *gradientFilter = [CIFilter filterWithName:@"CILinearGradient"];
CIColor *startColor = [CIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1.0];
CIColor *endColor = [CIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0];
[gradientFilter setValue:startColor forKey:@"inputColor0"];
[gradientFilter setValue:endColor forKey:@"inputColor1"];
CIVector *startVector = [CIVector vectorWithX:0 Y:0];
CIVector *endVector = [CIVector vectorWithX:self.frame.size.width Y:self.frame.size.height];
[gradientFilter setValue:startVector forKey:@"inputPoint0"];
[gradientFilter setValue:endVector forKey:@"inputPoint1"];
SKEffectNode *effectNode = [SKEffectNode node];
effectNode.blendMode = SKBlendModeAdd;
effectNode.filter = gradientFilter;
effectNode.shouldEnableEffects = YES;
effectNode.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);
[self addChild:effectNode];
Upvotes: 1
Views: 924