Class Entity

java.lang.Object
de.gurkenlabs.litiengine.entities.Entity
All Implemented Interfaces:
EntityRenderedListener, EntityRenderListener, IEntity, Tweenable, EventListener
Direct Known Subclasses:
CollisionEntity, Emitter, LightSource, MapArea, SoundSource, Spawnpoint

public abstract class Entity extends Object implements IEntity, EntityRenderListener, Tweenable
  • Field Details

  • Constructor Details

    • Entity

      protected Entity()
    • Entity

      protected Entity(boolean renderWithLayer)
    • Entity

      protected Entity(int mapId)
    • Entity

      protected Entity(String name)
    • Entity

      protected Entity(int mapId, String name)
  • Method Details

    • addTransformListener

      public void addTransformListener(EntityTransformListener listener)
      Description copied from interface: IEntity
      Adds a EntityTransformListener to receive transform events for this entity.
      Specified by:
      addTransformListener in interface IEntity
      Parameters:
      listener - The EntityTransformListener to add.
    • removeListener

      public void removeListener(EntityTransformListener listener)
      Description copied from interface: IEntity
      Removes a EntityTransformListener from this entity.
      Specified by:
      removeListener in interface IEntity
      Parameters:
      listener - The EntityTransformListener to remove.
    • addListener

      public void addListener(EntityListener listener)
      Description copied from interface: IEntity
      Adds a EntityListener to this entity that fires whenever the entity is added to or removed from the environment.
      Specified by:
      addListener in interface IEntity
      Parameters:
      listener - The EntityListener to add.
    • removeListener

      public void removeListener(EntityListener listener)
      Description copied from interface: IEntity
      Removes a EntityListener from this entity.
      Specified by:
      removeListener in interface IEntity
      Parameters:
      listener - The EntityListener to remove.
    • onRendered

      public void onRendered(EntityRenderedListener listener)
      Description copied from interface: IEntity
      Adds the specified EntityRenderedListener to receive events when entities were rendered.
      Specified by:
      onRendered in interface IEntity
      Parameters:
      listener - The EntityRenderedListener to add.
    • removeListener

      public void removeListener(EntityRenderedListener listener)
      Description copied from interface: IEntity
      Removes the specified EntityRenderedListener.
      Specified by:
      removeListener in interface IEntity
      Parameters:
      listener - The EntityRenderedListener to remove.
    • addEntityRenderListener

      public void addEntityRenderListener(EntityRenderListener listener)
      Description copied from interface: IEntity
      Adds the specified EntityRenderListener to receive events and callbacks about the rendering process of entities.
      Specified by:
      addEntityRenderListener in interface IEntity
      Parameters:
      listener - The EntityRenderListener to add.
    • removeListener

      public void removeListener(EntityRenderListener listener)
      Description copied from interface: IEntity
      Removes the specified EntityRenderListener.
      Specified by:
      removeListener in interface IEntity
      Parameters:
      listener - The EntityRenderListener to remove.
    • onMessage

      public void onMessage(EntityMessageListener listener)
      Description copied from interface: IEntity
      Adds a EntityMessageListener to receive messages sent to this entity.
      Specified by:
      onMessage in interface IEntity
      Parameters:
      listener - The EntityMessageListener to add.
    • onMessage

      public void onMessage(String message, EntityMessageListener listener)
      Description copied from interface: IEntity
      Adds a EntityMessageListener to receive messages with a specific content sent to this entity.
      Specified by:
      onMessage in interface IEntity
      Parameters:
      message - The message content to listen for.
      listener - The EntityMessageListener to add.
    • removeListener

      public void removeListener(EntityMessageListener listener)
      Description copied from interface: IEntity
      Removes a EntityMessageListener from this entity.
      Specified by:
      removeListener in interface IEntity
      Parameters:
      listener - The EntityMessageListener to remove.
    • attachControllers

      public void attachControllers()
      Description copied from interface: IEntity
      Attaches all controllers to this entity.
      Specified by:
      attachControllers in interface IEntity
    • detachControllers

      public void detachControllers()
      Description copied from interface: IEntity
      Detaches all controllers from this entity.
      Specified by:
      detachControllers in interface IEntity
    • getProperties

      public ICustomPropertyProvider getProperties()
      Description copied from interface: IEntity
      Gets the custom properties of the entity.
      Specified by:
      getProperties in interface IEntity
      Returns:
      The custom property provider of the entity.
    • getAngle

      public double getAngle()
      Specified by:
      getAngle in interface IEntity
    • animations

      public IEntityAnimationController<?> animations()
      Description copied from interface: IEntity
      Gets the entities animation controller.
      Specified by:
      animations in interface IEntity
      Returns:
      The entities animation controller or null if none was registered.
      See Also:
    • behavior

      public IBehaviorController behavior()
      Description copied from interface: IEntity
      Gets the behavior controller of the entity.
      Specified by:
      behavior in interface IEntity
      Returns:
      The behavior controller of the entity.
    • addController

      public void addController(IEntityController controller)
      Description copied from interface: IEntity
      Adds a controller to the entity.
      Specified by:
      addController in interface IEntity
      Parameters:
      controller - The controller to add.
    • setController

      public <T extends IEntityController> void setController(Class<T> clss, T controller)
      Description copied from interface: IEntity
      Sets a specific controller for the entity.
      Specified by:
      setController in interface IEntity
      Type Parameters:
      T - The type of the controller.
      Parameters:
      clss - The class of the controller.
      controller - The controller to set.
    • getController

      public <T extends IEntityController> T getController(Class<T> clss)
      Description copied from interface: IEntity
      Gets a specific controller of the entity.
      Specified by:
      getController in interface IEntity
      Type Parameters:
      T - The type of the controller.
      Parameters:
      clss - The class of the controller.
      Returns:
      The controller of the specified type.
    • getBoundingBox

      public Rectangle2D getBoundingBox()
      Description copied from interface: IEntity
      Gets the bounding box of the entity.
      Specified by:
      getBoundingBox in interface IEntity
      Returns:
      The bounding box of the entity.
    • getCenter

      public Point2D getCenter()
      Description copied from interface: IEntity
      Gets the center point of the entity.
      Specified by:
      getCenter in interface IEntity
      Returns:
      The center point of the entity.
    • getHeight

      public double getHeight()
      Description copied from interface: IEntity
      Gets the height of the entity.
      Specified by:
      getHeight in interface IEntity
      Returns:
      The height of the entity.
    • getLocation

      public Point2D getLocation()
      Description copied from interface: IEntity
      Gets the location of the entity.
      Specified by:
      getLocation in interface IEntity
      Returns:
      The location of the entity.
    • getMapId

      public int getMapId()
      Description copied from interface: IEntity
      Gets the map ID of the entity.
      Specified by:
      getMapId in interface IEntity
      Returns:
      The map ID of the entity.
    • getName

      public String getName()
      Description copied from interface: IEntity
      Gets the name of this entity.
      Specified by:
      getName in interface IEntity
      Returns:
      The name of this entity.
    • getRenderType

      public RenderType getRenderType()
      Description copied from interface: IEntity
      Gets the render type of the entity.
      Specified by:
      getRenderType in interface IEntity
      Returns:
      The render type of the entity.
    • getWidth

      public double getWidth()
      Description copied from interface: IEntity
      Gets the width of the entity.
      Specified by:
      getWidth in interface IEntity
      Returns:
      The width of the entity.
    • getX

      public double getX()
      Description copied from interface: IEntity
      Gets the X coordinate of the entity.
      Specified by:
      getX in interface IEntity
      Returns:
      The X coordinate of the entity.
    • getY

      public double getY()
      Description copied from interface: IEntity
      Gets the Y coordinate of the entity.
      Specified by:
      getY in interface IEntity
      Returns:
      The Y coordinate of the entity.
    • isVisible

      public boolean isVisible()
      Description copied from interface: IEntity
      Checks if the entity is visible.
      Specified by:
      isVisible in interface IEntity
      Returns:
      True if the entity is visible; otherwise false.
    • setVisible

      public void setVisible(boolean visible)
      Description copied from interface: IEntity
      Sets the visibility of the entity.
      Specified by:
      setVisible in interface IEntity
      Parameters:
      visible - True to make the entity visible; false to make it invisible.
    • actions

      public EntityActionMap actions()
      Description copied from interface: IEntity
      All registered actions of this entity.
      Specified by:
      actions in interface IEntity
      Returns:
      The EntityActionMap that holds all registered EntityActions for this instance.
      See Also:
    • perform

      public void perform(String actionName)
      Description copied from interface: IEntity
      Performs an EntityAction that was previously registered for this entity.

      Does nothing in case no action has been registered for the specified actionName.

      Specified by:
      perform in interface IEntity
      Parameters:
      actionName - The name of the action to be performed.
      See Also:
    • register

      public EntityAction register(String name, Runnable action)
      Description copied from interface: IEntity
      Registers an EntityAction with the specified name. It's later possible to execute these actions on the entity by using the Entity.perform(String actionName) method.
      Specified by:
      register in interface IEntity
      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:
    • 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
      Parameters:
      sender - The sender of the message.
      message - The message to send.
      Returns:
      The response to the message.
    • setHeight

      public void setHeight(double height)
      Description copied from interface: IEntity
      Sets the height of the entity.
      Specified by:
      setHeight in interface IEntity
      Parameters:
      height - The new height of the entity.
    • setLocation

      public void setLocation(double x, double y)
      Description copied from interface: IEntity
      Sets the location of the entity.
      Specified by:
      setLocation in interface IEntity
      Parameters:
      x - The X coordinate of the new location.
      y - The Y coordinate of the new location.
    • setLocation

      public void setLocation(Point2D location)
      Sets the map location.
      Specified by:
      setLocation in interface IEntity
      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.
      Specified by:
      setMapId in interface IEntity
      Parameters:
      mapId - The unique map ID for this IEntity
    • setName

      public void setName(String name)
      Description copied from interface: IEntity
      Sets the name of the entity.
      Specified by:
      setName in interface IEntity
      Parameters:
      name - The new name of the entity.
    • setRenderType

      public void setRenderType(RenderType renderType)
      Description copied from interface: IEntity
      Sets the render type of the entity.
      Specified by:
      setRenderType in interface IEntity
      Parameters:
      renderType - The new render type of the entity.
    • 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
      Parameters:
      width - The new width of the entity.
      height - The new height of the entity.
    • setWidth

      public void setWidth(double width)
      Description copied from interface: IEntity
      Sets the width of the entity.
      Specified by:
      setWidth in interface IEntity
      Parameters:
      width - The new width of the entity.
    • setX

      public void setX(double x)
      Description copied from interface: IEntity
      Sets the X coordinate of the entity.
      Specified by:
      setX in interface IEntity
      Parameters:
      x - The new X coordinate of the entity.
    • setY

      public void setY(double y)
      Description copied from interface: IEntity
      Sets the Y coordinate of the entity.
      Specified by:
      setY in interface IEntity
      Parameters:
      y - The new Y coordinate of the entity.
    • getTags

      public List<String> getTags()
      Description copied from interface: IEntity
      Gets the list of tags associated with the entity.
      Specified by:
      getTags in interface IEntity
      Returns:
      A list of tags associated with the entity.
    • hasTag

      public boolean hasTag(String tag)
      Description copied from interface: IEntity
      Checks if the entity has the specified tag.
      Specified by:
      hasTag in interface IEntity
      Parameters:
      tag - The tag to check for.
      Returns:
      True if the entity has the tag; otherwise false.
    • addTag

      public void addTag(String tag)
      Description copied from interface: IEntity
      Adds a tag to the entity.
      Specified by:
      addTag in interface IEntity
      Parameters:
      tag - The tag to add.
    • removeTag

      public void removeTag(String tag)
      Description copied from interface: IEntity
      Removes a tag from the entity.
      Specified by:
      removeTag in interface IEntity
      Parameters:
      tag - The tag to remove.
    • getTweenValues

      public float[] getTweenValues(TweenType tweenType)
      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 interface Tweenable
      Parameters:
      tweenType - The tween type of this interpolation, determining which values are modified.
      Returns:
      The array of current tween values.
    • setTweenValues

      public void setTweenValues(TweenType tweenType, float[] newValues)
      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 interface Tweenable
      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.
      Specified by:
      setAngle in interface IEntity
      Parameters:
      angle - the new angle in degrees
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getEnvironment

      public Environment 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 interface IEntity
      Returns:
      The entity's environment.
    • loaded

      public void loaded(Environment environment)
      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 interface IEntity
      Parameters:
      environment - The environment that the entity was added to
      See Also:
    • removed

      public void removed(Environment environment)
      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 interface IEntity
      Parameters:
      environment - The environment that the entity was removed from
      See Also:
    • isLoaded

      public boolean isLoaded()
      Description copied from interface: IEntity
      Indicates whether this entity is loaded on the currently active environment.
      Specified by:
      isLoaded in interface IEntity
      Returns:
      True if the entity is loaded on the game's currently active environment; otherwise false.
      See Also:
    • 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 specified RenderType and makes the entity dependent upon the visibility of its layer.

      This can only be used, of course, if the entity is related to a MapObject.
      This defaults to false if not explicitly set on the MapObject.

      Specified by:
      renderWithLayer in interface IEntity
      Returns:
      True if the entity should be rendered with the layer of the corresponding map object; otherwise false.
      See Also:
    • setRenderWithLayer

      public void setRenderWithLayer(boolean renderWithLayer)
      Description copied from interface: IEntity
      Sets whether the entity should be rendered with its layer.
      Specified by:
      setRenderWithLayer in interface IEntity
      Parameters:
      renderWithLayer - True to render with the layer; otherwise false.
    • rendering

      public void rendering(EntityRenderEvent event)
      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 interface EntityRenderListener
      Parameters:
      event - The event that contains the render data.
    • rendered

      public void rendered(EntityRenderEvent event)
      Description copied from interface: EntityRenderedListener
      This method gets called after an entity was rendered.
      Specified by:
      rendered in interface EntityRenderedListener
      Parameters:
      event - The event that contains the render data.
    • canRender

      public boolean canRender(IEntity entity)
      Description copied from interface: EntityRenderListener
      This method gets called before an Entity is about to be rendered. Returning false prevents the rendering of the specified entity.
      Specified by:
      canRender in interface EntityRenderListener
      Parameters:
      entity - The entity to be rendered.
      Returns:
      True if the entity should be rendered; otherwise false.
    • getControllers

      protected EntityControllers getControllers()