Class Entity<T extends Entity<?>>

java.lang.Object
com.codingame.gameengine.module.entities.Entity<T>
Type Parameters:
T - a subclass inheriting Entity, used in order to return this as a T instead of an Entity.
Direct Known Subclasses:
BlendableEntity, ContainerBasedEntity

public abstract class Entity<T extends Entity<?>> extends Object

A graphical entity, displayed on screen in the game's replay.

The graphical counterpart's coordinates are converted from world units to pixel coordinates.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the alpha of this Entity as a percentage.
    int
    Returns a unique identifier for this Entity.
    Returns this Entity's Mask.
     
    double
    Returns the rotation of this Entity in radians.
    double
    Returns the horizontal scale of this Entity as a percentage.
    double
    Returns the vertical scale of this Entity as a percentage.
    double
    Returns the horizontal skew of this Entity in radians.
    double
    Returns the vertical skew of this Entity in radians.
    int
    Returns the X coordinate of this Entity in world units.
    int
    Returns the Y coordinate of this Entity in world units.
    int
    Returns the z-index of this Entity used to compute the display order for overlapping entities.
    boolean
    Returns whether this Entity is flagged to be drawn on screen.
    protected static void
    requireValidAlpha(double alpha)
     
    protected static void
    requireValidColor(int color)
     
    protected T
     
    protected void
    set(String key, Object value)
     
    protected void
    set(String key, Object value, Curve curve)
     
    setAlpha(double alpha)
    Sets the alpha of this Entity as a percentage.
    setAlpha(double alpha, Curve curve)
    Sets the alpha of this Entity as a percentage.
    setMask(Mask mask)
    Sets a given Mask as this Entity's Mask.
    Sets a given SpriteAnimation as this Entity's Mask.
    setRotation(double rotation)
    Sets the rotation of this Entity in radians.
    setRotation(double rotation, Curve curve)
    Sets the rotation of this Entity in radians.
    setScale(double scale)
    Sets both the horizontal and vertical scale of this Entity to the same percentage.
    setScale(double scale, Curve curve)
    Sets both the horizontal and vertical scale of this Entity to the same percentage.
    setScaleX(double scaleX)
    Sets the horizontal scale of this Entity as a percentage.
    setScaleX(double scaleX, Curve curve)
    Sets the horizontal scale of this Entity as a percentage.
    setScaleY(double scaleY)
    Sets the vertical scale of this Entity as a percentage.
    setScaleY(double scaleY, Curve curve)
    Sets the vertical scale of this Entity as a percentage.
    setSkewX(double skewX)
    Sets the horizontal skew of this Entity in radians.
    setSkewX(double skewX, Curve curve)
    Sets the horizontal skew of this Entity in radians.
    setSkewY(double skewY)
    Sets the vertical skew of this Entity in radians.
    setSkewY(double skewY, Curve curve)
    Sets the vertical skew of this Entity in radians.
    setVisible(boolean visible)
    Flags this Entity to be drawn on screen or not.
    setX(int x)
    Sets the X coordinate of this Entity in world units.
    setX(int x, Curve curve)
    Sets the X coordinate of this Entity in world units.
    setY(int y)
    Sets the Y coordinate of this Entity in world units.
    setY(int y, Curve curve)
    Sets the Y coordinate of this Entity in world units.
    setZIndex(int zIndex)
    Sets the z-index of this Entity used to compute the display order for overlapping entities.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • self

      protected T self()
    • getId

      public int getId()
      Returns a unique identifier for this Entity.
      Returns:
      A unique identifier.
    • set

      protected void set(String key, Object value, Curve curve)
    • set

      protected void set(String key, Object value)
    • setX

      public T setX(int x)
      Sets the X coordinate of this Entity in world units.

      Default is 0.

      Parameters:
      x - the X coordinate for this Entity.
      Returns:
      this Entity.
    • setX

      public T setX(int x, Curve curve)
      Sets the X coordinate of this Entity in world units.

      Default is 0.

      Parameters:
      x - the X coordinate for this Entity.
      curve - the transition to animate between values of this property.
      Returns:
      this Entity.
    • setY

      public T setY(int y)
      Sets the Y coordinate of this Entity in world units.

      Default is 0.

      Parameters:
      y - the Y coordinate for this Entity.
      Returns:
      this Entity.
    • setY

      public T setY(int y, Curve curve)
      Sets the Y coordinate of this Entity in world units.

      Default is 0.

      Parameters:
      y - the Y coordinate for this Entity.
      curve - the transition to animate between values of this property.
      Returns:
      this Entity.
    • setZIndex

      public T setZIndex(int zIndex)

      Sets the z-index of this Entity used to compute the display order for overlapping entities.

      An Entity with a higher z-index is displayed over one with a smaller z-index.

      In case of equal values, the most recently created Entity will be on top.

      Default is 0.

      Parameters:
      zIndex - the z-index for this Entity.
      Returns:
      this Entity.
    • setScaleX

      public T setScaleX(double scaleX)
      Sets the horizontal scale of this Entity as a percentage.

      Default is 1.

      Parameters:
      scaleX - the horizontal scale for this Entity.
      Returns:
      this Entity.
    • setScaleX

      public T setScaleX(double scaleX, Curve curve)
      Sets the horizontal scale of this Entity as a percentage.

      Default is 1.

      Parameters:
      scaleX - the horizontal scale for this Entity.
      curve - the transition to animate between values of this property.
      Returns:
      this Entity.
    • setScaleY

      public T setScaleY(double scaleY)
      Sets the vertical scale of this Entity as a percentage.

      Default is 1.

      Parameters:
      scaleY - the vertical scale for this Entity.
      Returns:
      this Entity.
    • setScaleY

      public T setScaleY(double scaleY, Curve curve)
      Sets the vertical scale of this Entity as a percentage.

      Default is 1.

      Parameters:
      scaleY - the vertical scale for this Entity.
      curve - the transition to animate between values of this property.
      Returns:
      this Entity.
    • setSkewX

      public T setSkewX(double skewX)
      Sets the horizontal skew of this Entity in radians.

      Default is 0.

      Parameters:
      skewX - the horizontal skew for this Entity.
      Returns:
      this Entity.
    • setSkewX

      public T setSkewX(double skewX, Curve curve)
      Sets the horizontal skew of this Entity in radians.

      Default is 0.

      Parameters:
      skewX - the horizontal skew for this Entity.
      curve - the transition to animate between values of this property.
      Returns:
      this Entity.
    • setSkewY

      public T setSkewY(double skewY)
      Sets the vertical skew of this Entity in radians.

      Default is 0.

      Parameters:
      skewY - the vertical skew for this Entity.
      Returns:
      this Entity.
    • setSkewY

      public T setSkewY(double skewY, Curve curve)
      Sets the vertical skew of this Entity in radians.

      Default is 0.

      Parameters:
      skewY - the vertical skew for this Entity.
      curve - the transition to animate between values of this property.
      Returns:
      this Entity.
    • setAlpha

      public T setAlpha(double alpha)

      Sets the alpha of this Entity as a percentage.

      1 is opaque and 0 is invisible.

      Default is 1.

      Parameters:
      alpha - the alpha for this Entity.
      Returns:
      this Entity.
      Throws:
      IllegalArgumentException - if alpha < 0 or alpha > 1
    • setAlpha

      public T setAlpha(double alpha, Curve curve)

      Sets the alpha of this Entity as a percentage.

      1 is opaque and 0 is invisible.

      Default is 1.

      Parameters:
      alpha - the alpha for this Entity.
      curve - the transition to animate between values of this property.
      Returns:
      this Entity.
      Throws:
      IllegalArgumentException - if alpha < 0 or alpha > 1
    • setScale

      public T setScale(double scale)
      Sets both the horizontal and vertical scale of this Entity to the same percentage.
      Parameters:
      scale - the scale for this Entity.
      Returns:
      this Entity.
    • setScale

      public T setScale(double scale, Curve curve)
      Sets both the horizontal and vertical scale of this Entity to the same percentage.
      Parameters:
      scale - the scale for this Entity.
      curve - the transition to animate between values of this property.
      Returns:
      this Entity.
    • setRotation

      public T setRotation(double rotation)
      Sets the rotation of this Entity in radians.

      Default is 0.

      Parameters:
      rotation - the rotation for this Entity.
      Returns:
      this Entity.
    • setRotation

      public T setRotation(double rotation, Curve curve)
      Sets the rotation of this Entity in radians.

      Default is 0.

      Parameters:
      rotation - the rotation for this Entity.
      curve - the transition to animate between values of this property.
      Returns:
      this Entity.
    • setVisible

      public T setVisible(boolean visible)
      Flags this Entity to be drawn on screen or not.

      Default is true.

      Parameters:
      visible - the value for this Entity's visible flag.
      Returns:
      this Entity.
    • getX

      public int getX()
      Returns the X coordinate of this Entity in world units.
      Returns:
      the X coordinate of this Entity.
    • getY

      public int getY()
      Returns the Y coordinate of this Entity in world units.
      Returns:
      the Y coordinate of this Entity.
    • getZIndex

      public int getZIndex()
      Returns the z-index of this Entity used to compute the display order for overlapping entities.
      Returns:
      the z-index of this Entity.
    • getScaleX

      public double getScaleX()
      Returns the horizontal scale of this Entity as a percentage.

      Default is 1.

      Returns:
      the horizontal scale of this Entity.
    • getScaleY

      public double getScaleY()
      Returns the vertical scale of this Entity as a percentage.

      Default is 1.

      Returns:
      the vertical scale of this Entity.
    • getSkewX

      public double getSkewX()
      Returns the horizontal skew of this Entity in radians.

      Default is 0.

      Returns:
      the horizontal skew of this Entity.
    • getSkewY

      public double getSkewY()
      Returns the vertical skew of this Entity in radians.

      Default is 0.

      Returns:
      the vertical skew of this Entity.
    • getAlpha

      public double getAlpha()
      Returns the alpha of this Entity as a percentage.

      Default is 1.

      Returns:
      the alpha of this Entity.
    • getRotation

      public double getRotation()
      Returns the rotation of this Entity in radians.

      Default is 0.

      Returns:
      the rotation coordinate of this Entity.
    • isVisible

      public boolean isVisible()
      Returns whether this Entity is flagged to be drawn on screen.

      Default is true.

      Returns:
      the value of the visible flag of this Entity.
    • setMask

      public T setMask(Mask mask)

      Sets a given Mask as this Entity's Mask.

      Note: texture masks will only work on browsers which support WebGL
      Parameters:
      mask - the mask.
      Returns:
      this Entity.
    • setMask

      public T setMask(SpriteAnimation animation)

      Sets a given SpriteAnimation as this Entity's Mask.

      Note: texture masks will only work on browsers which support WebGL
      Parameters:
      animation - the mask.
      Returns:
      this Entity.
    • getMask

      public Mask getMask()

      Returns this Entity's Mask.

      A Mask can be:
      • a Shape
      • a Sprite
      • a SpriteAnimation

      Default is null.

      Returns:
      this Entity's Mask.
    • requireValidAlpha

      protected static void requireValidAlpha(double alpha)
    • requireValidColor

      protected static void requireValidColor(int color)
    • getParent

      public Optional<ContainerBasedEntity<?>> getParent()
      Returns:
      the Group or BufferedGroup which contains this entity