Class LightingEngine

java.lang.Object
com.csse3200.game.lighting.LightingEngine
All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable, Renderable, Comparable<Renderable>

public class LightingEngine extends Object implements com.badlogic.gdx.utils.Disposable, Renderable
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    LightingEngine(box2dLight.RayHandler rayHandler, com.badlogic.gdx.graphics.OrthographicCamera camera)
     
    LightingEngine(com.badlogic.gdx.physics.box2d.World world, com.badlogic.gdx.graphics.OrthographicCamera camera)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    applyDefaultLightingSettings(box2dLight.Light light)
    Applies default lighting settings to a light source.
    int
     
    box2dLight.ChainLight
    createChainLight(float[] chain, float dist, int dir, com.badlogic.gdx.graphics.Color color)
    Create a new chain light.
    box2dLight.ConeLight
    createConeLight(float x, float y, float dist, float dir, float cone, com.badlogic.gdx.graphics.Color color)
    Create a new cone light (sector).
    box2dLight.DirectionalLight
    createDirectionalLight(float dir, com.badlogic.gdx.graphics.Color color)
    Create a new directional light.
    box2dLight.PointLight
    createPointLight(float x, float y, float dist, com.badlogic.gdx.graphics.Color color)
    Create a new point light (circle).
    void
    Disposes
    int
    Layer to be rendered in.
    box2dLight.RayHandler
     
    float
    Z index controls rendering order within a layer.
    void
    Render the lighting effects.
    void
    render(com.badlogic.gdx.graphics.g2d.SpriteBatch sb)
    Render the renderable.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • LightingEngine

      public LightingEngine(box2dLight.RayHandler rayHandler, com.badlogic.gdx.graphics.OrthographicCamera camera)
    • LightingEngine

      public LightingEngine(com.badlogic.gdx.physics.box2d.World world, com.badlogic.gdx.graphics.OrthographicCamera camera)
  • Method Details

    • render

      public void render(com.badlogic.gdx.graphics.g2d.SpriteBatch sb)
      Description copied from interface: Renderable
      Render the renderable. Should be called only by the renderer, not manually.
      Specified by:
      render in interface Renderable
      Parameters:
      sb - Batch to render to.
    • render

      public void render()
      Render the lighting effects.
    • getRayHandler

      public box2dLight.RayHandler getRayHandler()
      Returns:
      The RayHandler used by the engine.
    • compareTo

      public int compareTo(Renderable o)
      Specified by:
      compareTo in interface Comparable<Renderable>
    • getLayer

      public int getLayer()
      Description copied from interface: Renderable
      Layer to be rendered in. Higher layers will be rendered on top of lower layers.
      Specified by:
      getLayer in interface Renderable
      Returns:
      layer
    • getZIndex

      public float getZIndex()
      Description copied from interface: Renderable
      Z index controls rendering order within a layer. Higher Z index is drawn on top.
      Specified by:
      getZIndex in interface Renderable
      Returns:
      Z index
    • dispose

      public void dispose()
      Disposes
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable
    • createPointLight

      public box2dLight.PointLight createPointLight(float x, float y, float dist, com.badlogic.gdx.graphics.Color color)
      Create a new point light (circle).
      Parameters:
      x - The game world x position of the light
      y - The game world y position of the light
      dist - The distance the light travels or radius if it's not blocked
      color - The color of the point light
      Returns:
      A reference to the created PointLight.
    • createConeLight

      public box2dLight.ConeLight createConeLight(float x, float y, float dist, float dir, float cone, com.badlogic.gdx.graphics.Color color)
      Create a new cone light (sector).
      Parameters:
      x - The game world x position of the light
      y - The game world y position of the light
      dist - The distance the light travels or radius if it's not blocked
      dir - The direction the light should face in degrees
      cone - The sector angle in degrees
      color - The color of the light
      Returns:
      A reference to the created ConeLight.
    • createDirectionalLight

      public box2dLight.DirectionalLight createDirectionalLight(float dir, com.badlogic.gdx.graphics.Color color)
      Create a new directional light. Infinite distance light source coming from a certain direction.
      Parameters:
      dir - The direction the light should face in degrees
      color - The color of the light
      Returns:
      A reference to the created DirectionalLight.
    • createChainLight

      public box2dLight.ChainLight createChainLight(float[] chain, float dist, int dir, com.badlogic.gdx.graphics.Color color)
      Create a new chain light. Infinite distance light source coming from a certain direction.
      Parameters:
      chain - float array of (x, y) vertices from which rays will be evenly distributed
      dist - The distance the light travels or radius if it's not blocked
      dir - The direction of rays: 1 is left, -1 is right
      color - The color of the light
      Returns:
      A reference to the created ChainLight.
    • applyDefaultLightingSettings

      public static void applyDefaultLightingSettings(box2dLight.Light light)
      Applies default lighting settings to a light source. The default settings are: - setIgnoreAttachedBody(true) which will ensure light does not collide with fixtures of the body it is attached to - setSoftnessLength(3f) which will mean the light will bleed through objects to some degree - setContactFilter(PhysicsLayer.DEFAULT, PhysicsLayer.NONE, PhysicsLayer.ALL) which will make the light collide with all physics bodies.