1

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!

Ryan_DS
  • 750
  • 7
  • 28
  • Possible duplicate of [how I check collision with box2dlights in libgdx?](http://stackoverflow.com/questions/31910000/how-i-check-collision-with-box2dlights-in-libgdx) – sorifiend May 09 '17 at 04:28
  • If the other possible duplicate answer doesn’t make sense then: Get the cone light details and then do a quick calculation based on the point of the light, the radius, the direction and the angle of the cone and you will be able to work out what objects are effected by the light and base your rendering on that. – sorifiend May 09 '17 at 04:30
  • I'll see if I can use a formula based on a semi-circle in order to detect objects in the area. Thanks for the idea – Ryan_DS May 09 '17 at 11:15

2 Answers2

1

You can use the Box2D RayCasting from the source of the light in the direction of the light and see what it hits. If circumstances is right you could also use the built in Frustum culling in libGDX Cameras

0

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.

Ryan_DS
  • 750
  • 7
  • 28