making a sprite/body invisible when it doesn't get any light ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Phil88n
:warning: Old Version Published before Godot 3 was released.

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

:bust_in_silhouette: Reply From: Tinkleberg

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!

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

Phil88n | 2017-06-20 04:46

there is no such thing like get_light(), only get_light_mask(), and it wont work

Phil88n | 2017-06-20 04:49

:bust_in_silhouette: Reply From: kintrix

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;

Although this works in theory, I’m experiencing some bugs with it.