While playing around with the box2dlights with libGDX, I have managed to get it all up and running, but have a problem with the shadow rendering.

This is what I currently have atm:

With the lighting on: enter image description here

With the lighting off: enter image description here

What I want is to have the shadow be rendered so that the body is visible when the light is shone upon it, so that the platform is visible.

Here's some of my code that I use to create and render my lighting:

    // world lighting creation
    rayHandler = new RayHandler(physicsWorld, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    // world lighting rendering
    rayHandler.setCombinedMatrix(cameraWorld.combined.scale(PIXELS_TO_METERS / SCALE_TO_SIZE, PIXELS_TO_METERS / SCALE_TO_SIZE, 0),
            cameraWorld.position.x / PIXELS_TO_METERS * SCALE_TO_SIZE, cameraWorld.position.y / PIXELS_TO_METERS * SCALE_TO_SIZE,
            cameraWorld.viewportWidth, cameraWorld.viewportHeight);

    // player torch light creation
    torchLight = new ConeLight(rayHandler, 50, Color.WHITE, 50 / SCALE_TO_SIZE, x / SCALE_TO_SIZE, y / SCALE_TO_SIZE, angle, 35);

Any thoughts?

  • 1
    \$\begingroup\$ Does this similar question on StackOverflow help at all? \$\endgroup\$ – DMGregory Nov 30 '18 at 12:36
  • \$\begingroup\$ @DMGregory Yes! Thank you! I'll make my answer but you can mark it as a duplicate if you want. \$\endgroup\$ – PlatyPi Nov 30 '18 at 17:31

Thanks to this link here,

I set the softness, torchLight.setSoftnessLength(2.5f);

and turned on the blur, torchLight.setBlur(true);

which fixed it, what I wanted.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.