Package com.csse3200.game.lighting
Class LightingEngine
java.lang.Object
com.csse3200.game.lighting.LightingEngine
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
,Renderable
,Comparable<Renderable>
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLightingEngine
(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 TypeMethodDescriptionstatic 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
dispose()
Disposesint
getLayer()
Layer to be rendered in.box2dLight.RayHandler
float
Z index controls rendering order within a layer.void
render()
Render the lighting effects.void
render
(com.badlogic.gdx.graphics.g2d.SpriteBatch sb) Render the renderable.
-
Field Details
-
LIGHTING_LAYER
public static final int LIGHTING_LAYER- See Also:
-
-
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 interfaceRenderable
- 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
- Specified by:
compareTo
in interfaceComparable<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 interfaceRenderable
- 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 interfaceRenderable
- Returns:
- Z index
-
dispose
public void dispose()Disposes- Specified by:
dispose
in interfacecom.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 lighty
- The game world y position of the lightdist
- The distance the light travels or radius if it's not blockedcolor
- 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 lighty
- The game world y position of the lightdist
- The distance the light travels or radius if it's not blockeddir
- The direction the light should face in degreescone
- The sector angle in degreescolor
- 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 degreescolor
- 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 distributeddist
- The distance the light travels or radius if it's not blockeddir
- The direction of rays: 1 is left, -1 is rightcolor
- 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.
-