javaandroidlibgdxbox2dbox2dlights

LibGdx Box2dLights: How to make Chain Lights emit light in all directions?


The "ChainLight" Class has a parameter in its constructor which is called "rayDirection":

ChainLight(rayHandler, rays, Color, distance, rayDirection, float[] vertices)

Apparently, if it is set to "1", the light direction is left and if it is "-1", the light direction is right.

Question: Is there a way to make it emit light in ALL directions (including up and down) without creating new instances?


Solution

  • The ChainLight is intended to allow you to build arbitrary shapes with light emitting out from them.

    The direction of left or right ( 1 or -1 ) will be determined by which direction you define your vertices in, So you could define a chain like so:

    v2(0,1)______________v3(1,1)
         |               |
         |               |   
         |               |
    v1(0,0)v5(0,0)_______v4(1,0)
    

    Hopefully my ascii art is clear enough. We have a chain made up of 4 lines defined by 5 coordinates (1 and 5 are the same coordinates to create a closed shape). And because the vertices wind around in a clockwise direction, the direction of the light should be left - I think - to make the light shine outwards rather than inwards. Give it a try.

    This hopefully gives you the left, right, up and down kind of thing you are looking for.