且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 iOS 中使用 sprite kit 创建一个 alpha 蒙版

更新时间:2023-02-02 10:25:54

我有个主意……希望对你有帮助.

I have an idea... I hope it would help.

用你想要的从白到黑的渐变制作一个PNG,不透明.

Make a PNG with the gradient you want from white to black with no transparency.

为您想要的每个灯光使用带有 png 的单独精灵节点,并将它们全部添加到 SKEffectNode 或 SKCropNode 节点.哪个都没有关系,因为它们都在单独的上下文中呈现.将每个精灵节点设置为屏幕混合模式.

Use a separate sprite node with the png for each light you want and add them all to a SKEffectNode or SKCropNode node. It doesn't matter which since they are both rendered in a separate context. Set each sprite node to screen blending mode.

然后,在将父级 SKEffectNode 或 SKCropNode 添加到场景中时,将其设置为乘法混合模式.

Then, when adding the parent SKEffectNode or SKCropNode to the scene, set it to multiply blend mode.

最后,加网会将灯光"很好地融合在一起,而乘法会使白色区域变得透明.

In the end, the screening will merge the "lights" together nicely, while the multiply will make the white area transparent.