Class Entity2D

All Implemented Interfaces:
Behavior, Renderable, Closeable, AutoCloseable

public final class Entity2D extends Entity2DContainer
Represents a 2D entity within a game or application. This class extends Entity2DContainer and provides functionality for managing components, updating, rendering, and transforming the entity within its hierarchy.
  • Method Details

    • onUpdate

      public void onUpdate(ContextTime time)
      Description copied from interface: Behavior
      This method is called when the behavior needs to be updated with the current time. It is typically used to perform any necessary calculations or updates based on the current time.
      Specified by:
      onUpdate in interface Behavior
      Overrides:
      onUpdate in class Entity2DContainer
      Parameters:
      time - The current time context.
    • render

      public void render(Renderer renderer)
      Description copied from interface: Renderable
      Renders the object using the provided Renderer.
      Specified by:
      render in interface Renderable
      Overrides:
      render in class Entity2DContainer
      Parameters:
      renderer - The renderer to use for rendering the object.
    • hierarchyTransform

      public Transform2D hierarchyTransform()
      Calculates the transformations applied to this entity by its parent and itself.
      Returns:
      The transformations applied to this entity.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class Entity2DContainer
      Throws:
      IOException
    • containsTag

      public boolean containsTag(String tag)
      Checks if a given tag is present in the array of tags.
      Parameters:
      tag - The tag to check for.
      Returns:
      True if the tag is present in the array of tags, false otherwise.
    • component

      public <T extends ComponentBehavior> T component(Class<T> componentType, int index)
      Gets the component of the specified type at the specified renderIndex.
      Parameters:
      componentType - The type of component to retrieve.
      index - The renderIndex of the component to retrieve.
      Returns:
      The component of the specified type at the specified renderIndex, or null if no such component exists.
    • component

      public <T extends ComponentBehavior> T component(Class<T> componentType)
      Gets the first component of the specified type.
      Type Parameters:
      T - The type of component to retrieve.
      Parameters:
      componentType - The type of component to retrieve.
      Returns:
      The first component of the specified type, or null if no such component exists.
    • transform

      public Transform2D transform()
      Gets the transformations applied to this entity.
      Returns:
      The transformations applied to this entity.
    • components

      public ComponentBehavior[] components()
      Gets the array of components that this entity manages.
      Returns:
      The array of components that this entity manages.
    • parent

      public Entity2DContainer parent()
      Gets the parent entity of this entity, or null if it has no parent.
      Returns:
      The parent entity of this entity, or null if it has no parent.
    • renderIndex

      public int renderIndex()
      Gets the renderIndex of this entity.
      Returns:
      The renderIndex of this entity.
    • setRenderIndex

      public Entity2D setRenderIndex(int renderIndex)
      Sets the renderIndex of this entity.
      Parameters:
      renderIndex - The new renderIndex for this entity.
      Returns:
      This entity, for method chaining.
    • tags

      public String[] tags()
      Gets the array of tags that describe this entity.
      Returns:
      The array of tags that describe this entity.
    • visible

      public boolean visible()
      Gets the visibility of this entity.
      Returns:
      The visibility of this entity.
    • setVisible

      public Entity2D setVisible(boolean visible)
      Sets the visibility of this entity.
      Parameters:
      visible - True to make this entity visible, false to hide it.
      Returns:
      This entity, for method chaining.