Class LightSource

java.lang.Object
de.gurkenlabs.litiengine.entities.Entity
de.gurkenlabs.litiengine.entities.LightSource
All Implemented Interfaces:
EntityRenderedListener, EntityRenderListener, IEntity, IRenderable, Tweenable, EventListener

public class LightSource extends Entity implements IRenderable
This class represents a light source in an environment. It extends the Entity class and implements IRenderable interface. It provides methods to render light sources and shadows.
  • Field Details

    • TOGGLE_MESSAGE

      public static final String TOGGLE_MESSAGE
      Message identifier used to toggle this light source via the engine's messaging system.
      See Also:
    • DEFAULT_INTENSITY

      public static final int DEFAULT_INTENSITY
      Default light intensity used when none is specified.
      See Also:
  • Constructor Details

    • LightSource

      public LightSource(int intensity, Color lightColor, LightSource.Type shapeType, boolean activated)
      Constructor for the LightSource class.
      Parameters:
      intensity - The intensity of this instance.
      lightColor - The color of this instance.
      shapeType - The shape type of this instance.
      activated - A flag indicating whether this light is activated by default.
  • Method Details

    • activate

      public void activate()
      Activates the light source.
    • deactivate

      public void deactivate()
      Deactivates the light source.
    • getColor

      public Color getColor()
      Gets the color of the light emitted by this source.
      Returns:
      the light color
    • getGradientPaint

      public RadialGradientPaint getGradientPaint()
      Builds the radial gradient paint used to render the light cone, fading from the source color outwards.
      Returns:
      the gradient paint
    • getIntensity

      public int getIntensity()
      Gets the light intensity. Returns 0 when the light source is inactive.
      Returns:
      the current intensity
    • getLightShape

      public Shape getLightShape()
      Gets the geometric shape representing this light source's emission area.
      Returns:
      the light shape
    • getLightShapeType

      public LightSource.Type getLightShapeType()
      Gets the type of shape used by this light source.
      Returns:
      the shape type
    • isActive

      public boolean isActive()
      Returns whether the light source is currently active.
      Returns:
      true if active
    • setColor

      public void setColor(Color color)
      Sets the color of the light emitted by this source and refreshes the affected ambient layers.
      Parameters:
      color - the new color
    • setIntensity

      public void setIntensity(int intensity)
      Sets the intensity of the light and refreshes the affected ambient layers.
      Parameters:
      intensity - the new intensity
    • setLightShapeType

      public void setLightShapeType(LightSource.Type shapeType)
      Sets the shape type of the light source.
      Parameters:
      shapeType - the new shape type
    • setSize

      public void setSize(double width, double height)
      Description copied from interface: IEntity
      Sets the size of the entity.
      Specified by:
      setSize in interface IEntity
      Overrides:
      setSize in class Entity
      Parameters:
      width - The new width of the entity.
      height - The new height of the entity.
    • setLocation

      public void setLocation(Point2D location)
      Description copied from class: Entity
      Sets the map location.
      Specified by:
      setLocation in interface IEntity
      Overrides:
      setLocation in class Entity
      Parameters:
      location - the new map location
    • toggle

      public void toggle()
      Toggles the light source between active and inactive states.
    • sendMessage

      public String sendMessage(Object sender, String message)
      Description copied from interface: IEntity
      Sends a message from the specified sender to this entity.
      Specified by:
      sendMessage in interface IEntity
      Overrides:
      sendMessage in class Entity
      Parameters:
      sender - The sender of the message.
      message - The message to send.
      Returns:
      The response to the message.
    • render

      public void render(Graphics2D graphic)
      Description copied from interface: IRenderable

      Renders the visual contents of this instance onto the provided graphics context.

      If an Entity implements this interface, this method will be called right after the entity was rendered from the environment. Allowing for a custom rendering mechanism.

      This interface can be implemented in general by anything that should be rendered to the game's screen.

      Specified by:
      render in interface IRenderable
      Parameters:
      graphic - The current graphics object onto which this instance will render its visual contents.
      See Also: