The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+9 votes

I want to partially reveal a sprite and programmatically show it completely along the time.
Mask area I want to use is a circle and want to hide the parts of the sprite that are outside the circle
How can I achieve that?

in Engine by (659 points)

Sorry I can't help. The closest stuff I did was to paint only a part of a sprite, but it had to be a rectangular area.

Note that this looks like an easy task for shaders.

1 Answer

+19 votes
Best answer

To use 2d mask in Godot you need to use Light2d.

  1. Prepare mask in graphic editor, use white / alpha. Let the part that should be visible be white, the part that should be invisible should be totally transparent.
  2. Add Light2D node to the scene, ensure it's enabled (Enabled = true)
  3. Load your mask to the light with Texture property.
  4. Set light to mask mode (Mode->Mask)
  5. In Range section of the light take a note on what is the value of 'Item Mask
  6. Add ordinary sprite node that should be affected by the mask, setup it.
  7. In 'Canvas Item' section ensure that Light Mask property is corresponding to Item Mask property of the light.

If you will have any problems check one of the demos, which illustrates how to use masks, demo is called "Using lights as mask", you can find it here: http://godotengine.org/download (Demos and Examples)

by (1,299 points)
selected by

You could do the same thing with a material on any CanvasItem. Just multiply the alpha by your mask texture.

Or do it in a material without an image mask by using the UVs, like in the later third of this video: https://www.youtube.com/watch?v=VnBNBMfk9HM

Thank you, this comment helped us a lot in our project. One thing to notice is that in the Demo project the Set light mode is set to "Mix" and not "Mask" (your step 4). In our project we had to set it to "Mix" for the Light Mask to work correctly. When set to "Mask" it fades all images and show the Bg color

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.