简体   繁体   English

SKSpriteKit混合目标Alpha

[英]SKSpriteKit blending destination alpha

Here is the source code in SKScene constructor: 这是SKScene构造函数中的源代码:

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. 我希望在sprite2覆盖的区域上获得绿色,因为我设置了混合模式SKBlendModeSubtract,这将导致混合后目标alpha为0.0。 I need help to get it or a reason why it doesn't work as expected? 我需要帮助才能获取它,或者为什么它无法按预期运行? Thanks in advance 提前致谢

The Subtract blend mode subtracts color values, not alpha values. 减法混合模式会减去颜色值,而不是alpha值。 The intersection you see should be black because the color of the intersection is (1,0,0)-(1,0,0)=(0,0,0). 您看到的相交应该是黑色的,因为相交的颜色是(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. SKCropNode可以执行此操作,但可能不是您想要的方式。 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? 您可能需要看以下问题之一以获得一些想法: 在SpriteKit(SKCropNode)中对蒙版图像进行动画处理是否可以在Sprite Kit中使用圆形(SKShapeNode)作为蒙版?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM