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 interface
AnimationCompleteCallback is aFunctionalInterface
for defining functionality that happens when an animation completes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Constant for telling theSpriteAnimatorComponent
to 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 SpriteKeyFrame
void
playAnimation
(String id) Starts playing the animation with desired id.void
restart()
Restarts the current animation.setAnimationCompleteCallback
(SpriteAnimatorComponent.AnimationCompleteCallback animationCompleteCallback) Sets theSpriteAnimatorComponent.AnimationCompleteCallback
that happens when an animation finishes playing.void
tickAnimation
(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, wait
Methods inherited from interface technology.sola.ecs.Component
afterDeserialize
-
Field Details
-
CONTINUOUS
public static final int CONTINUOUSConstant for telling theSpriteAnimatorComponent
to 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
- theSpriteKeyFrame
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 activeloops
- the number of loopsactiveAnimationKeyFrames
- theSpriteKeyFrame
array
-
-
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
- theSpriteKeyFrame
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 idloops
- the number of loopsspriteKeyFrames
- theSpriteKeyFrame
array- Returns:
- this
-
setAnimationCompleteCallback
public SpriteAnimatorComponent setAnimationCompleteCallback(SpriteAnimatorComponent.AnimationCompleteCallback animationCompleteCallback) Sets theSpriteAnimatorComponent.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
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
-