This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

so, I added a sprite with lightoccluder2d and a moveable light2d, but I want the sprite to be invisible when there is no light hit it.. how can I do it? i am using a bright orange color as background

in Engine by (18 points)
edited by

2 Answers

0 votes

Perhaps you can check for the amount of light hitting the object and adjust the opacity of your object based on that value.

I'm not sure of the specifics but it could be something like:

self.set_opacity(0 + self.lightvalue)

0 making the sprite invisible and the self.lightvalue being the value of light hitting the sprite (I'm not sure what the name for this value is actually called). So that when self.lightvalue is 0 (No light), the opacity is 0 + 0 which would make the sprite invisible.

Sorry for not having more specifics to help you with, but hopefully that helps some!

by (70 points)

wait, how do i check for amount of light hitting the sprite ?

there is no such thing like getlight(), only getlight_mask(), and it wont work

0 votes

If I'm not mistaken, now there is a way to accomplish this with shaders.
All you need to do is add a ShaderMaterial to the given node, and add a Shader to it.

In the shader, you just wirte:

shader_type canvas_item;
render_mode light_only;

BUT!
Although this works in theory, I'm experiencing some bugs with it.

by (14 points)
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.