Class SpriteAnimatorComponent

java.lang.Object
technology.sola.engine.graphics.components.animation.SpriteAnimatorComponent
All Implemented Interfaces:
technology.sola.ecs.Component

@NullMarked public class SpriteAnimatorComponent extends Object implements technology.sola.ecs.Component
SpritesAnimatorComponent is a Component that contains data for controlling how a SpriteComponent animates between frames. Multiple different animations can be added and played as needed.
  • Field Details

  • Constructor Details

    • SpriteAnimatorComponent

      public SpriteAnimatorComponent(String activeAnimationId, SpriteKeyFrame... activeAnimationKeyFrames)
      Creates a SpriteAnimatorComponent with animation id and an array of key frames. The animation will loop CONTINUOUS.
      Parameters:
      activeAnimationId - the animation id that starts as active
      activeAnimationKeyFrames - the SpriteKeyFrame array
    • SpriteAnimatorComponent

      public SpriteAnimatorComponent(String activeAnimationId, int loops, SpriteKeyFrame... activeAnimationKeyFrames)
      Creates a SpriteAnimatorComponent with animation id and an array of key frames. The animation will loop the desired amount of times.
      Parameters:
      activeAnimationId - the animation id that starts as active
      loops - the number of loops
      activeAnimationKeyFrames - the SpriteKeyFrame array
  • Method Details

    • addAnimation

      public SpriteAnimatorComponent addAnimation(String id, SpriteKeyFrame... spriteKeyFrames)
      Adds a new animation with animation id and an array of key frames. The animation will loop CONTINUOUS.
      Parameters:
      id - the animation id
      spriteKeyFrames - the SpriteKeyFrame array
      Returns:
      this
    • addAnimation

      public SpriteAnimatorComponent addAnimation(String id, int loops, SpriteKeyFrame... spriteKeyFrames)
      Adds a new animation with animation id and an array of key frames. The animation will loop the desired amount of times.
      Parameters:
      id - the animation id
      loops - the number of loops
      spriteKeyFrames - the SpriteKeyFrame array
      Returns:
      this
    • setAnimationCompleteCallback

      public SpriteAnimatorComponent setAnimationCompleteCallback(SpriteAnimatorComponent.AnimationCompleteCallback animationCompleteCallback)
      Sets the SpriteAnimatorComponent.AnimationCompleteCallback that happens when an animation finishes playing.
      Parameters:
      animationCompleteCallback - the animation complete callback
      Returns:
      this
    • tickAnimation

      public void tickAnimation(float deltaTime)
      Ticks the animation state by a delta time.
      Parameters:
      deltaTime - the time elapsed since previous update
    • playAnimation

      public void playAnimation(String id)
      Starts playing the animation with desired id.
      Parameters:
      id - the id of the animation to play
    • restart

      public void restart()
      Restarts the current animation.
    • getCurrentFrame

      public @Nullable SpriteKeyFrame getCurrentFrame()
      Returns:
      the currently active SpriteKeyFrame
    • getActiveAnimationId

      public @Nullable String getActiveAnimationId()
      Returns:
      the currently active animation id