Getting Started
Preparations
Since the @box2d/lights
package is written without a dependency to @box2d/core
(so it can be used by other physics librares), you'll need to create some glue code. I've preparaed a sample implementation on GitHub. Feel free to just copy/paste that into your code-base.
Setup
In your setup code, write:
const rayHandler = new RayHandlerImpl(world, glContext, camera.width / 4, camera.height / 4, viewport.x, viewport.y);
Enable/Disable Shadows
You can disable shadows with:
rayHandler.setShadows(false);
Creating Lights
Ambient Light
You can set the ambient light with
rayHandler.setAmbientLight(r, g, b, a);
rayHandler.setBlurNum(3);
Point Lights
This creates a new white point light. RAY_NUM being the number of ray lights (e.g.: 4 is a simple star)
const light = new PointLight(rayHandler, RAYS_NUM, new LightColor(1, 1, 1, 1), lightDistance, x, y);
Rendering
In your render loop after everything is drawn that you want to be lit:
rayHandler.setCombinedMatrix(camera.combined, center.x, center.y, camera.width, camera.height);
rayHandler.updateAndRender();
Cleanup
Remember to dispose the ray handler (and lights, etc.) when cleaning up:
rayHandler.dispose();