Module technology.sola.engine
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAnimationCompleteCallback is aFunctionalInterfacefor defining functionality that happens when an animation completes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConstant for telling theSpriteAnimatorComponentto continuously loop the animation. -
Constructor Summary
ConstructorsConstructorDescriptionSpriteAnimatorComponent(String activeAnimationId, int loops, SpriteKeyFrame... activeAnimationKeyFrames) Creates a SpriteAnimatorComponent with animation id and an array of key frames.SpriteAnimatorComponent(String activeAnimationId, SpriteKeyFrame... activeAnimationKeyFrames) Creates a SpriteAnimatorComponent with animation id and an array of key frames. -
Method Summary
Modifier and TypeMethodDescriptionaddAnimation(String id, int loops, SpriteKeyFrame... spriteKeyFrames) Adds a new animation with animation id and an array of key frames.addAnimation(String id, SpriteKeyFrame... spriteKeyFrames) Adds a new animation with animation id and an array of key frames.@Nullable String@Nullable SpriteKeyFramevoidplayAnimation(String id) Starts playing the animation with desired id.voidrestart()Restarts the current animation.setAnimationCompleteCallback(SpriteAnimatorComponent.AnimationCompleteCallback animationCompleteCallback) Sets theSpriteAnimatorComponent.AnimationCompleteCallbackthat happens when an animation finishes playing.voidtickAnimation(float deltaTime) Ticks the animation state by a delta time.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface technology.sola.ecs.Component
afterDeserialize
-
Field Details
-
CONTINUOUS
public static final int CONTINUOUSConstant for telling theSpriteAnimatorComponentto continuously loop the animation.- See Also:
-
-
Constructor Details
-
SpriteAnimatorComponent
public SpriteAnimatorComponent(String activeAnimationId, SpriteKeyFrame... activeAnimationKeyFrames) Creates a SpriteAnimatorComponent with animation id and an array of key frames. The animation will loopCONTINUOUS.- Parameters:
activeAnimationId- the animation id that starts as activeactiveAnimationKeyFrames- theSpriteKeyFramearray
-
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 activeloops- the number of loopsactiveAnimationKeyFrames- theSpriteKeyFramearray
-
-
Method Details
-
addAnimation
Adds a new animation with animation id and an array of key frames. The animation will loopCONTINUOUS.- Parameters:
id- the animation idspriteKeyFrames- theSpriteKeyFramearray- 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 idloops- the number of loopsspriteKeyFrames- theSpriteKeyFramearray- Returns:
- this
-
setAnimationCompleteCallback
public SpriteAnimatorComponent setAnimationCompleteCallback(SpriteAnimatorComponent.AnimationCompleteCallback animationCompleteCallback) Sets theSpriteAnimatorComponent.AnimationCompleteCallbackthat 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
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
- Returns:
- the currently active
SpriteKeyFrame
-
getActiveAnimationId
- Returns:
- the currently active animation id
-