Class AnimationPlayer

All Implemented Interfaces:
Behavior, Renderable, Closeable, AutoCloseable

public final class AnimationPlayer extends ComponentBehavior
The AnimationPlayer class is a component behavior that handles the playing of animations by updating the texture rectangle with the current frame.
  • Constructor Details

    • AnimationPlayer

      public AnimationPlayer()
  • Method Details

    • onUpdate

      public void onUpdate(ContextTime time)
      This method is called every frame to update the animation player.
      Specified by:
      onUpdate in interface Behavior
      Overrides:
      onUpdate in class ComponentBehavior
      Parameters:
      time - The context time, containing delta time.
    • getAnimation

      public Animation getAnimation()
      Returns the currently playing animation.
      Returns:
      The currently playing animation.
    • setAnimation

      public AnimationPlayer setAnimation(Animation animation)
      Sets the current animation to the given animation.
      Parameters:
      animation - The animation to set.
      Returns:
      This AnimationPlayer instance.
    • animation

      public Animation animation()
      Returns the currently playing animation.
      Returns:
      The currently playing animation.
    • toSwitchAnimation

      public Animation toSwitchAnimation()
      Returns the animation that will be played after the current animation finishes.
      Returns:
      The animation that will be played after the current animation finishes.
    • setToSwitchAnimation

      public AnimationPlayer setToSwitchAnimation(Animation toSwitchAnimation)
      Sets the animation that will be played after the current animation finishes.
      Parameters:
      toSwitchAnimation - The animation to set.
      Returns:
      This AnimationPlayer instance.
    • actualFrame

      public int actualFrame()
      Returns the index of the current frame in the animation.
      Returns:
      The index of the current frame in the animation.
    • setActualFrame

      public AnimationPlayer setActualFrame(int actualFrame)
      Sets the index of the current frame in the animation.
      Parameters:
      actualFrame - The index of the frame to set.
      Returns:
      This AnimationPlayer instance.
    • toChange

      public double toChange()
      Returns the time since the last frame change.
      Returns:
      The time since the last frame change.
    • setToChange

      public AnimationPlayer setToChange(double toChange)
      Sets the time since the last frame change.
      Parameters:
      toChange - The time to set.
      Returns:
      This AnimationPlayer instance.