Reputation: 431
Here is the source code in SKScene constructor:
self.backgroundColor = [SKColor greenColor];
SKSpriteNode* sprite1 = [[SKSpriteNode alloc] initWithColor: [SKColor colorWithRed: 0.5 green:0.5 blue:0.5 alpha:1.0] size: CGSizeMake(500.0, 500.0)];
sprite1.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
[self addChild: sprite1];
SKSpriteNode* sprite2 = [[SKSpriteNode alloc] initWithColor: [SKColor colorWithRed: 1.0 green:1.0 blue:1.0 alpha: 1.0] size: CGSizeMake(100.0, 100.0)];
sprite2.blendMode = SKBlendModeSubtract;
[sprite1 addChild: sprite2];
I expected to get a green color on area covered by sprite2, as I set the blend mode SKBlendModeSubtract which should cause destination alpha to be 0.0 after blending. I need help to get it or a reason why it doesn't work as expected? Thanks in advance
Upvotes: 0
Views: 479
Reputation: 3317
The Subtract blend mode subtracts color values, not alpha values. The intersection you see should be black because the color of the intersection is (1,0,0)-(1,0,0)=(0,0,0).
What you are looking for is layer mask. SKCropNode does this, but maybe not in the way you want. You may want to look at one of these questions to get some ideas: Animate masked image in SpriteKit (SKCropNode), Is it possible to use a circle (SKShapeNode) as a mask in Sprite Kit?
Upvotes: 1