Class LightingComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.lighting.components.LightingComponent
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a component which allows light sources to be attached to an entity. -
Method Summary
Modifier and TypeMethodDescriptionattach
(box2dLight.PositionalLight light) Attaches a light source to the entity's center position.attach
(box2dLight.PositionalLight light, com.badlogic.gdx.math.Vector2 offset) Attaches a light source to the entity with an offset from its center position.static box2dLight.ConeLight
createConeLight
(float dist, float dir, float cone, com.badlogic.gdx.graphics.Color color) Create a new cone light (sector).static box2dLight.PointLight
createPointLight
(float dist, com.badlogic.gdx.graphics.Color color) Create a new point light (circle).boolean
detach
(box2dLight.PositionalLight light) Detaches a light source from the entity.void
dispose()
Remove light sources on disposeList
<box2dLight.PositionalLight> Get the light source corresponding to this LightComponentList
<com.badlogic.gdx.math.Vector2> Get the offset of the light from the entity/physics body centervoid
update()
Update the position (and direction in future) of light to match the entity.Methods inherited from class com.csse3200.game.components.Component
create, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
Constructor Details
-
LightingComponent
public LightingComponent()Create a component which allows light sources to be attached to an entity.
-
-
Method Details
-
attach
Attaches a light source to the entity's center position.- Parameters:
light
- The light source.
-
attach
public LightingComponent attach(box2dLight.PositionalLight light, com.badlogic.gdx.math.Vector2 offset) Attaches a light source to the entity with an offset from its center position.- Parameters:
light
- The light source.offset
- Relative offset from entity/physics body center.
-
getLights
Get the light source corresponding to this LightComponent- Returns:
- LightComponent Light source
-
detach
public boolean detach(box2dLight.PositionalLight light) Detaches a light source from the entity.- Parameters:
light
- The light source.- Returns:
- true if the light source was attached to the entity
-
getOffsets
Get the offset of the light from the entity/physics body center- Returns:
- Light offset
-
update
public void update()Update the position (and direction in future) of light to match the entity. This is only necessary if the entity doesn't have a body. -
createPointLight
public static box2dLight.PointLight createPointLight(float dist, com.badlogic.gdx.graphics.Color color) Create a new point light (circle).- Parameters:
dist
- 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 static box2dLight.ConeLight createConeLight(float dist, float dir, float cone, com.badlogic.gdx.graphics.Color color) Create a new cone light (sector).- Parameters:
dist
- The distance the light travels or radius if it's not blockedcone
- The sector angle in degreescolor
- The color of the point light- Returns:
- A reference to the created ConeLight.
-
dispose
public void dispose()Remove light sources on dispose
-