Layers in Sprite Kit

Is it possible to do something like layers in Sprite Kit, where blend modes like multiply is processed in each layer individually? I am trying to make shapes only visible when they are intersecting other shapes (only the intersecting part should be visible), and I've tried to do this with the multiply blend mode. The problem is that the multiply blend mode also affects the background, so it's visible everywhere, not only when intersecting. My thought was that if I could have layers, I could have the background in one layer, and the shapes in another layer such that the multiply blend mode don't affect the background.

Answered by QuinceyMorris in 11213022

It seems to me you can keep the intersection nodes "off-screen" (that is, don't add them as descendants of the scene node), but with a SKNode as parent. Ask the parent for its image, and use that to create a node that you add to the scene.


Or, a bit more convoluted but more automatic if the child nodes are moving relative to each other, use the parent SKNode to provide the mask for a clip node. I'm not sure if you can do this without duplicates of the child nodes, but it'd be something to experiment with.

Accepted Answer

It seems to me you can keep the intersection nodes "off-screen" (that is, don't add them as descendants of the scene node), but with a SKNode as parent. Ask the parent for its image, and use that to create a node that you add to the scene.


Or, a bit more convoluted but more automatic if the child nodes are moving relative to each other, use the parent SKNode to provide the mask for a clip node. I'm not sure if you can do this without duplicates of the child nodes, but it'd be something to experiment with.

Layers in Sprite Kit
 
 
Q