Skip to content

Lighting

miguel edited this page Apr 5, 2019 · 4 revisions

Lighting is an essential part to make environments more real and add day and night cycles to your game. Also you can use it to write horror or puzzle games. braingdx implements box2dlights very easily:

LightingManager lightingManager = context.getLightingManager();
// Set ambient color to red (ff0000)
lightingManager.setAmbientLight(Color.RED);
// Add a blue point light at [100,100] with radius=250
lightingManager.addPointLight("my-point-light", new Vector2(100, 100), 250f, Color.BLUE);
// Remove the light again
lightingManager.removePointLight("my-point-light");

It is also possible to dynamically add lights and attach them to GameObject instances:

GameObject object = context.getGameWorld().addGameObject();
getBehaviorManager().apply(
     object, 
     new PointLightBehavior(200f, Color.RED, lightingManager
);

The light will now update its position automatically whenever the object is moved in the world.

Lighting configuration

By default braingdx has uses a default configuration to set up its lighting system. It is possible to define a custom configuration:

LightingConfig config = new LightingConfig();
config.shadows(false) // disable shadows
      .diffuseLighting(true) // enable diffuse
      .blur(false) // disable blur shadows
      .gammaCorrection(true) // use gamma correction
      .culling(false); // disable culling

// Apply configuration
context.getLightingManager().setConfig(config);

lighting

Clone this wiki locally