Class ComponentBehavior

java.lang.Object
com.xebisco.yield.AbstractBehavior
com.xebisco.yield.ComponentBehavior
All Implemented Interfaces:
Behavior, Renderable, Closeable, AutoCloseable
Direct Known Subclasses:
AbstractRenderable, AnimationPlayer, AudioPlayer, Collider2D, Joint2D, PhysicsBody

public abstract class ComponentBehavior extends AbstractBehavior implements Renderable
Abstract class representing a behavior that can be attached to an Entity2D. It provides methods for updating, rendering, and accessing entity-related information.
  • Constructor Details

    • ComponentBehavior

      public ComponentBehavior()
  • Method Details

    • onCreate

      public void onCreate()
      Called when the behavior is created.
    • onLateUpdate

      public void onLateUpdate(ContextTime time)
      Called after all onUpdate(ContextTime) calls.
      Parameters:
      time - The context time.
    • onStart

      public void onStart()
      Called when the entity starts.
      Specified by:
      onStart in interface Behavior
    • onUpdate

      public void onUpdate(ContextTime time)
      Called every frame.
      Specified by:
      onUpdate in interface Behavior
      Parameters:
      time - The context time.
    • close

      public void close() throws IOException
      Called when the behavior is closed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - If an I/O error occurs.
    • render

      public void render(Renderer renderer)
      Renders the behavior.
      Specified by:
      render in interface Renderable
      Parameters:
      renderer - The renderer.
    • entity

      public Entity2D entity()
      Returns the entity this behavior is attached to.
      Returns:
      The entity.
    • application

      public Application application()
      Returns the application this behavior belongs to.
      Returns:
      The application.
    • setEntity

      public ComponentBehavior setEntity(Entity2D entity)
      Sets the entity this behavior is attached to.
      Parameters:
      entity - The entity.
      Returns:
      This behavior.
    • transform

      public Transform2D transform()
      Returns the transform of the entity this behavior is attached to.
      Returns:
      The transform.
    • renderIndex

      public int renderIndex()
      Returns the render index of the entity this behavior is attached to.
      Returns:
      The render index.
    • setRenderIndex

      public ComponentBehavior setRenderIndex(int index)
      Sets the render index of the entity this behavior is attached to.
      Parameters:
      index - The render index.
      Returns:
      This behavior.
    • component

      public <T extends ComponentBehavior> T component(Class<T> componentType)
      Returns a component of the specified type attached to the entity this behavior is attached to.
      Parameters:
      componentType - The type of the component.
      Returns:
      The component.
    • component

      public <T extends ComponentBehavior> T component(Class<T> componentType, int index)
      Returns a component of the specified type and index attached to the entity this behavior is attached to.
      Parameters:
      componentType - The type of the component.
      index - The index of the component.
      Returns:
      The component.
    • texture

      public final AbstractTexture texture(String path, TextureFilter filter)
      Returns a texture loaded on demand from the specified path and filter.
      Parameters:
      path - The path of the texture.
      filter - The texture filter.
      Returns:
      The texture.
    • texture

      public final AbstractTexture texture(String path)
      Returns a texture loaded on demand from the specified path with a default linear filter.
      Parameters:
      path - The path of the texture.
      Returns:
      The texture.