Class Entity
java.lang.Object
de.gurkenlabs.litiengine.entities.Entity
- All Implemented Interfaces:
EntityRenderedListener
,EntityRenderListener
,IEntity
,Tweenable
,java.util.EventListener
- Direct Known Subclasses:
CollisionEntity
,Emitter
,LightSource
,MapArea
,SoundSource
,Spawnpoint
public abstract class Entity
extends java.lang.Object
implements IEntity, EntityRenderListener, Tweenable
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ANY_MESSAGE
Constructor Summary
Method Summary
Modifier and Type Method Description EntityActionMap
actions()
All registered actions of this entity.void
addController(IEntityController controller)
void
addEntityRenderListener(EntityRenderListener listener)
Adds the specified entity render listener to receive events and callbacks about the rendering process of entities.void
addListener(EntityListener listener)
void
addTag(java.lang.String tag)
void
addTransformListener(EntityTransformListener listener)
IEntityAnimationController<?>
animations()
Gets the entities animation controller.void
attachControllers()
IBehaviorController
behavior()
boolean
canRender(IEntity entity)
This method gets called before anEntity
is about to be rendered.void
detachControllers()
double
getAngle()
java.awt.geom.Rectangle2D
getBoundingBox()
java.awt.geom.Point2D
getCenter()
<T extends IEntityController>
TgetController(java.lang.Class<T> clss)
protected EntityControllers
getControllers()
Environment
getEnvironment()
Gets the environment the entity was loaded to or null if it is not loaded.double
getHeight()
java.awt.geom.Point2D
getLocation()
int
getMapId()
java.lang.String
getName()
Gets the name of this entity.ICustomPropertyProvider
getProperties()
RenderType
getRenderType()
java.util.List<java.lang.String>
getTags()
float[]
getTweenValues(TweenType tweenType)
Gets one or many values from the target object associated to the given tween type.double
getWidth()
double
getX()
double
getY()
boolean
hasTag(java.lang.String tag)
boolean
isLoaded()
Indicates whether this entity is loaded on the currently active environment.boolean
isVisible()
void
loaded(Environment environment)
This method provides the possibility to implement behavior whenever this entity was added to the environment.void
onMessage(EntityMessageListener listener)
void
onMessage(java.lang.String message, EntityMessageListener listener)
void
onRendered(EntityRenderedListener listener)
Adds the specified entity rendered listener to receive events when entities were rendered.void
perform(java.lang.String actionName)
Performs anEntityAction
that was previously registered for this entity.EntityAction
register(java.lang.String name, java.lang.Runnable action)
Registers anEntityAction
with the specified name.void
removed(Environment environment)
This method provides the possibility to implement behavior whenever this entity was removed from the environment.void
removeListener(EntityListener listener)
void
removeListener(EntityMessageListener listener)
void
removeListener(EntityRenderedListener listener)
Removes the specified entity rendered listener.void
removeListener(EntityRenderListener listener)
Removes the specified entity render listener.void
removeListener(EntityTransformListener listener)
void
removeTag(java.lang.String tag)
void
rendered(EntityRenderEvent event)
This method gets called after an entity was rendered.void
rendering(EntityRenderEvent event)
This method gets called after all rendering checks have successfully passed and right before the entity is about to be rendered.boolean
renderWithLayer()
Determines whether this entity is being rendered with the layer it's originating from.java.lang.String
sendMessage(java.lang.Object sender, java.lang.String message)
void
setAngle(double angle)
Sets the angle (in degrees) in which the entity is directed.<T extends IEntityController>
voidsetController(java.lang.Class<T> clss, T controller)
void
setHeight(double height)
void
setLocation(double x, double y)
void
setLocation(java.awt.geom.Point2D location)
Sets the map location.void
setMapId(int mapId)
Sets an id which should only be filled when an entity gets added due to map information.void
setName(java.lang.String name)
void
setRenderType(RenderType renderType)
void
setRenderWithLayer(boolean renderWithLayer)
void
setSize(double width, double height)
void
setTweenValues(TweenType tweenType, float[] newValues)
This method is called in a Tween's update() method to set the new interpolated values.void
setVisible(boolean visible)
void
setWidth(double width)
void
setX(double x)
void
setY(double y)
java.lang.String
toString()
Field Details
ANY_MESSAGE
public static final java.lang.String ANY_MESSAGE- See Also:
- Constant Field Values
Constructor Details
Method Details
addTransformListener
- Specified by:
addTransformListener
in interfaceIEntity
removeListener
- Specified by:
removeListener
in interfaceIEntity
addListener
- Specified by:
addListener
in interfaceIEntity
removeListener
- Specified by:
removeListener
in interfaceIEntity
onRendered
Description copied from interface:IEntity
Adds the specified entity rendered listener to receive events when entities were rendered.- Specified by:
onRendered
in interfaceIEntity
- Parameters:
listener
- The listener to add.
removeListener
Description copied from interface:IEntity
Removes the specified entity rendered listener.- Specified by:
removeListener
in interfaceIEntity
- Parameters:
listener
- The listener to remove.
addEntityRenderListener
Description copied from interface:IEntity
Adds the specified entity render listener to receive events and callbacks about the rendering process of entities.- Specified by:
addEntityRenderListener
in interfaceIEntity
- Parameters:
listener
- The listener to add.
removeListener
Description copied from interface:IEntity
Removes the specified entity render listener.- Specified by:
removeListener
in interfaceIEntity
- Parameters:
listener
- The listener to remove.
onMessage
onMessage
removeListener
- Specified by:
removeListener
in interfaceIEntity
attachControllers
public void attachControllers()- Specified by:
attachControllers
in interfaceIEntity
detachControllers
public void detachControllers()- Specified by:
detachControllers
in interfaceIEntity
getProperties
- Specified by:
getProperties
in interfaceIEntity
getAngle
public double getAngle()animations
Description copied from interface:IEntity
Gets the entities animation controller.- Specified by:
animations
in interfaceIEntity
- Returns:
- The entities animation controller or null if none was registered.
- See Also:
RenderEngine.renderEntity(java.awt.Graphics2D, IEntity)
behavior
addController
- Specified by:
addController
in interfaceIEntity
setController
- Specified by:
setController
in interfaceIEntity
getController
- Specified by:
getController
in interfaceIEntity
getBoundingBox
public java.awt.geom.Rectangle2D getBoundingBox()- Specified by:
getBoundingBox
in interfaceIEntity
getCenter
public java.awt.geom.Point2D getCenter()getHeight
public double getHeight()getLocation
public java.awt.geom.Point2D getLocation()- Specified by:
getLocation
in interfaceIEntity
getMapId
public int getMapId()getName
public java.lang.String getName()Description copied from interface:IEntity
Gets the name of this entity.getRenderType
- Specified by:
getRenderType
in interfaceIEntity
getWidth
public double getWidth()getX
public double getX()getY
public double getY()isVisible
public boolean isVisible()setVisible
public void setVisible(boolean visible)- Specified by:
setVisible
in interfaceIEntity
actions
Description copied from interface:IEntity
All registered actions of this entity.- Specified by:
actions
in interfaceIEntity
- Returns:
- The EntityActionMap that holds all registered EntityActions for this instance.
- See Also:
EntityActionMap
,IEntity.register(String, Runnable)
perform
public void perform(java.lang.String actionName)Description copied from interface:IEntity
Performs anEntityAction
that was previously registered for this entity.Does nothing in case no action has been registered for the specified
actionName
.- Specified by:
perform
in interfaceIEntity
- Parameters:
actionName
- The name of the action to be performed.- See Also:
IEntity.actions()
,IEntity.register(String, Runnable)
register
Description copied from interface:IEntity
Registers anEntityAction
with the specified name. It's later possible to execute these actions on the entity by using theEntity.perform(String actionName)
method.- Specified by:
register
in interfaceIEntity
- Parameters:
name
- The name of the action to be registered.action
- The action to be performed by the entity.- Returns:
- The created EntityAction instance; or null if the name or action parameter were invalid.
- See Also:
IEntity.perform(String)
,IEntity.actions()
sendMessage
public java.lang.String sendMessage(java.lang.Object sender, java.lang.String message)- Specified by:
sendMessage
in interfaceIEntity
setHeight
public void setHeight(double height)setLocation
public void setLocation(double x, double y)- Specified by:
setLocation
in interfaceIEntity
setLocation
public void setLocation(java.awt.geom.Point2D location)Sets the map location.- Specified by:
setLocation
in interfaceIEntity
- Parameters:
location
- the new map location
setMapId
public void setMapId(int mapId)Sets an id which should only be filled when an entity gets added due to map information.setName
public void setName(java.lang.String name)setRenderType
- Specified by:
setRenderType
in interfaceIEntity
setSize
public void setSize(double width, double height)setWidth
public void setWidth(double width)setX
public void setX(double x)setY
public void setY(double y)getTags
public java.util.List<java.lang.String> getTags()hasTag
public boolean hasTag(java.lang.String tag)addTag
public void addTag(java.lang.String tag)removeTag
public void removeTag(java.lang.String tag)getTweenValues
Description copied from interface:Tweenable
Gets one or many values from the target object associated to the given tween type. It is used by the Tween Engine to determine starting values.- Specified by:
getTweenValues
in interfaceTweenable
- Parameters:
tweenType
- The tween type of this interpolation, determining which values are modified.- Returns:
- The array of current tween values.
setTweenValues
Description copied from interface:Tweenable
This method is called in a Tween's update() method to set the new interpolated values.- Specified by:
setTweenValues
in interfaceTweenable
- Parameters:
tweenType
- The tween type of this interpolation, determining which values are modified.newValues
- The new values determined by the tween equation.
setAngle
public void setAngle(double angle)Description copied from interface:IEntity
Sets the angle (in degrees) in which the entity is directed.toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
getEnvironment
Description copied from interface:IEntity
Gets the environment the entity was loaded to or null if it is not loaded.- Specified by:
getEnvironment
in interfaceIEntity
- Returns:
- The entity's environment.
loaded
Description copied from interface:IEntity
This method provides the possibility to implement behavior whenever this entity was added to the environment.- Specified by:
loaded
in interfaceIEntity
- Parameters:
environment
- The environment that the entity was added to- See Also:
IEntity.addListener(EntityListener)
removed
Description copied from interface:IEntity
This method provides the possibility to implement behavior whenever this entity was removed from the environment.- Specified by:
removed
in interfaceIEntity
- Parameters:
environment
- The environment that the entity was removed from- See Also:
IEntity.addListener(EntityListener)
isLoaded
public boolean isLoaded()Description copied from interface:IEntity
Indicates whether this entity is loaded on the currently active environment.- Specified by:
isLoaded
in interfaceIEntity
- Returns:
- True if the entity is loaded on the game's currently active environment; otherwise false.
- See Also:
GameWorld.environment()
,IEntity.loaded(Environment)
,IEntity.removed(Environment)
renderWithLayer
public boolean renderWithLayer()Description copied from interface:IEntity
Determines whether this entity is being rendered with the layer it's originating from. This ignores the specifiedRenderType
and makes the entity dependent upon the visibility of it's layer.This can only be used, of course, if the entity is related to a
MapObject
.
This defaults tofalse
if not explicitly set on theMapObject
.- Specified by:
renderWithLayer
in interfaceIEntity
- Returns:
- True if the entity should be rendered with the layer of the corresponding map object; otherwise false.
- See Also:
ILayer.isVisible()
,IMapObjectLayer.getMapObjects()
,Environment.getEntitiesByLayer(int)
,Environment.getEntitiesByLayer(String)
setRenderWithLayer
public void setRenderWithLayer(boolean renderWithLayer)- Specified by:
setRenderWithLayer
in interfaceIEntity
rendering
Description copied from interface:EntityRenderListener
This method gets called after all rendering checks have successfully passed and right before the entity is about to be rendered.- Specified by:
rendering
in interfaceEntityRenderListener
- Parameters:
event
- The event that contains the render data.
rendered
Description copied from interface:EntityRenderedListener
This method gets called after an entity was rendered.- Specified by:
rendered
in interfaceEntityRenderedListener
- Parameters:
event
- The event that contains the render data.
canRender
Description copied from interface:EntityRenderListener
This method gets called before anEntity
is about to be rendered. Returning false prevents the rendering of the specified entity.- Specified by:
canRender
in interfaceEntityRenderListener
- Parameters:
entity
- The entity to be rendered.- Returns:
- True if the entity should be rendered; otherwise false.
getControllers