问题
It is possible to detect when a body is under light? ( Collision with the light and a body )
How I check this with libgdx?
Sorry for my english...
回答1:
It could be easy to implements with raycasting :
- With a point light, you have to perform a raycast from your body object to the light object, if the first returned body is the light then your object is under light.
- With a directional (infinite) light you have to raycast from your object body toward light direction opposite, if raycast not returning bodies then your object is under light.
- With Cone lights, it's the same as point lights but you also need to check angle with that light.
Notes :
- If your object body is big, you may perform multiple raycasts (from different positions).
- If you have multiple lights, you need to perform multiple raycasts as well.
来源:https://stackoverflow.com/questions/31910000/how-i-check-collision-with-box2dlights-in-libgdx