Search code examples
javalibgdxbox2draycastingbox2dlights

Access rays cast by Box2D Lights


I am currently developing a game with the Box2D lights library and LibGDX.

Everything is currently fine, however, I'm having difficulty accessing the rays from the ConeLight.

I wish to stop rendering objects if they are not in the ray of the light. Is there any way to access the rays the library is casting so I can work out if an object is in the way of the light?

A quick search through the JavaDocs and the internet yielded no results. Maybe through reflection?
Methods like light.setContactFiltering() exist however they only stop certain objects from getting affected by the light.

I do not wish to ray cast myself to detect objects but instead, try to access the existing rays cast in order to try and save computational power.

Thank you for the help!


Solution

  • After some more research, I realized I skipped over a method in the Light class.

    If anyone wants to check if a point is within a light, you can use light.contains(x,y)

    Hope this comes in handy.