How do I mask a group of sprites?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By epark009

I have a face sprite with sprites for eyes and a mouth inside. They’re set in a hierarchy so that when the face moves, the face features move with it. When the face turns, I would like the eyes and mouth to not appear outside of the face’s boundary. This could be accomplished with a mask, but it looks like Godot Engine doesn’t have an easy masking feature.

I’ve searched online and some people suggested using a Light2D. This works for the most part, except for a few problems. It creates a thin outline at the edges of the mask, which appears above everything on the same layer. It also causes the sprites inside the Light2D to completely ignore other Light2D effects, so shadows and such don’t affect the face.

This thread provided a nice example using shaders: Easy and flexible way to make sprite masks · Issue #23763 · godotengine/godot · GitHub When I try to use this shader myself, it completely wipes out the face. If I try to change some values around, it kinda looks like it provides an separate mask for each facial feature, instead of just one mask. I set each facial feature to inherit the parent’s shader, so I guess that makes sense. But that’s also not what I want.

I want a single mask affecting multiple sprites in a hierarchy, and I want the mask to be at a specific position. Is there another way to accomplish this?

Working on the assumption that this is impossible, I’ll just have to design my sprites without masking in mind. It’ll take a little more work but it’ll actually end up looking better in the end I think.

epark009 | 2019-05-19 21:23