0
votes

I wanted to ask if you can use box2d lights so you can see only objects that are in the lights area. For example i have a flashlight and only want to see game objects in the light. I managed to do something like this but the problem is that the sprites of the game objects lose their color intensity because I render lights on top of sprites and the game itself doesn't look good because of this (even though it is the effect that i want).I used box2d bodies with user data containing sprites. I can't figure any way out. Is there any proper way to use box2d lights library to make these objects visible and with their real color? (I am setting lights to X-rays to do this; also I am using it with libgdx in java).

1
I'm not really sure what you're asking- you ask if something is possible, but then you say you've already done it but don't like the effect. What does your code currently do? What do you want it to do differently? Try posting an MCVE and some example images, and we'll go from there. - Kevin Workman
I have something like a maze and a character. I want everything dark and the only way to see in the maze is with the flash light which the player holds and which is a cone light. The problem is that to hide the sprites you have to render the light first in the loop and then to render the sprites, because libgdx draws things in the order you put them. Also when you render lights everything but the lighted area becomes dark. The problem as I stated before is that doing this the sprites which are in the flash light's area don't have the color they would have if I would draw them normally. - Andrew
Sorry for double comment, but the first one is too long and i wanted to add some very basic code to let people know what I was trying to say. Basic code: public void render(float delta) { renderSprites(); renderLights();} and the render lights would be a world with a rayHandler attached and the method rayHandler.updateAndRender(); would be called after drawing the sprites which would cause the color to be really washed off when you put the light on the sprites. - Andrew

1 Answers

0
votes

It may be because the default setting is to not use diffuseLight. You have to set rayHandler.useDiffuseLight(true).

Libgdx and Box2DLights - too bright + colors grayed out