Class LightingComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.lighting.components.LightingComponent

public class LightingComponent extends Component
  • Field Summary

    Fields inherited from class com.csse3200.game.components.Component

    enabled, entity
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a component which allows light sources to be attached to an entity.
  • Method Summary

    Modifier and Type
    Method
    Description
    attach(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
    Remove light sources on dispose
    List<box2dLight.PositionalLight>
    Get the light source corresponding to this LightComponent
    List<com.badlogic.gdx.math.Vector2>
    Get the offset of the light from the entity/physics body center
    void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • LightingComponent

      public LightingComponent()
      Create a component which allows light sources to be attached to an entity.
  • Method Details

    • attach

      public LightingComponent attach(box2dLight.PositionalLight light)
      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

      public List<box2dLight.PositionalLight> 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

      public List<com.badlogic.gdx.math.Vector2> 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.
      Overrides:
      update in class Component
    • 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 blocked
      color - 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 blocked
      cone - The sector angle in degrees
      color - The color of the point light
      Returns:
      A reference to the created ConeLight.
    • dispose

      public void dispose()
      Remove light sources on dispose
      Overrides:
      dispose in class Component