-
Notifications
You must be signed in to change notification settings - Fork 4
libGDX Example Code
Julien Villegas edited this page Dec 16, 2017
·
4 revisions
Copy the box2dlights.jar to your libGDX projects 'libs/' folder. Add box2dlights.jar to the projects Build Path.
Within your libGDX project source, add the following:
Globals
public RayHandler rayHandler;
create() or show()
this.rayHandler = new RayHandler(this.world);
RayHandler.setGammaCorrection(true); // enable or disable gamma correction
RayHandler.useDiffuseLight(false); // enable or disable diffused lighting
this.rayHandler.setBlur(true); // enabled or disable blur
this.rayHandler.setBlurNum(1); // set number of gaussian blur passes
this.rayHandler.setShadows(true); // enable or disable shadow
this.rayHandler.setCulling(true); // enable or disable culling
this.rayHandler.setAmbientLight(0.9f); // set default ambient light
// Two different ways to create a PointLight
new PointLight(rayHandler, 500, Color.RED, 50, -5, 10);
new PointLight(rayHandler, 500, new Color(1f, 0.5f, 1f, 1f), 150, 0, 30);
render()
Be sure to call this after the objects you wish to render shadows for and NOT inside begin/end statements.
this.rayHandler.setCombinedMatrix(this.camera.combined);
this.rayHandler.updateAndRender();
An example of using Box2dLight on LibGDX.info