Class LightSource
java.lang.Object
de.gurkenlabs.litiengine.entities.Entity
de.gurkenlabs.litiengine.entities.LightSource
- All Implemented Interfaces:
EntityRenderedListener, EntityRenderListener, IEntity, IRenderable, Tweenable, EventListener
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum representing the type of light source. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault light intensity used when none is specified.static final StringMessage identifier used to toggle this light source via the engine's messaging system.Fields inherited from class Entity
ANY_MESSAGE -
Constructor Summary
ConstructorsConstructorDescriptionLightSource(int intensity, Color lightColor, LightSource.Type shapeType, boolean activated) Constructor for the LightSource class. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate()Activates the light source.voidDeactivates the light source.getColor()Gets the color of the light emitted by this source.Builds the radial gradient paint used to render the light cone, fading from the source color outwards.intGets the light intensity.Gets the geometric shape representing this light source's emission area.Gets the type of shape used by this light source.booleanisActive()Returns whether the light source is currently active.voidrender(Graphics2D graphic) Renders the visual contents of this instance onto the provided graphics context.sendMessage(Object sender, String message) Sends a message from the specified sender to this entity.voidSets the color of the light emitted by this source and refreshes the affected ambient layers.voidsetIntensity(int intensity) Sets the intensity of the light and refreshes the affected ambient layers.voidsetLightShapeType(LightSource.Type shapeType) Sets the shape type of the light source.voidsetLocation(Point2D location) Sets the map location.voidsetSize(double width, double height) Sets the size of the entity.voidtoggle()Toggles the light source between active and inactive states.Methods inherited from class Entity
actions, addController, addEntityRenderListener, addListener, addTag, addTransformListener, animations, attachControllers, behavior, canRender, detachControllers, getAngle, getBoundingBox, getCenter, getController, getControllers, getEnvironment, getHeight, getLocation, getMapId, getName, getProperties, getRenderType, getTags, getTweenValues, getWidth, getX, getY, hasTag, isLoaded, isVisible, loaded, onActionPerformed, onMessage, onMessage, onRendered, perform, register, removeActionPerformedListener, removed, removeListener, removeListener, removeListener, removeListener, removeListener, removeTag, rendered, rendering, renderWithLayer, setAngle, setController, setHeight, setLocation, setMapId, setName, setRenderType, setRenderWithLayer, setTweenValues, setVisible, setWidth, setX, setY, toString
-
Field Details
-
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_INTENSITYDefault light intensity used when none is specified.- See Also:
-
-
Constructor Details
-
LightSource
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
Gets the color of the light emitted by this source.- Returns:
- the light color
-
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. Returns0when the light source is inactive.- Returns:
- the current intensity
-
getLightShape
Gets the geometric shape representing this light source's emission area.- Returns:
- the light shape
-
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:
trueif active
-
setColor
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
Sets the shape type of the light source.- Parameters:
shapeType- the new shape type
-
setSize
-
setLocation
Description copied from class:EntitySets the map location.- Specified by:
setLocationin interfaceIEntity- Overrides:
setLocationin classEntity- Parameters:
location- the new map location
-
toggle
public void toggle()Toggles the light source between active and inactive states. -
sendMessage
Description copied from interface:IEntitySends a message from the specified sender to this entity.- Specified by:
sendMessagein interfaceIEntity- Overrides:
sendMessagein classEntity- Parameters:
sender- The sender of the message.message- The message to send.- Returns:
- The response to the message.
-
render
Description copied from interface:IRenderableRenders the visual contents of this instance onto the provided graphics context.
If an
Entityimplements 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:
renderin interfaceIRenderable- Parameters:
graphic- The current graphics object onto which this instance will render its visual contents.- See Also:
-