public class Animation<T> extends Object
An Animation stores a list of objects representing an animated sequence, e.g. for running or jumping. Each object in the Animation is called a key frame, and multiple key frames make up the animation.
The animation's type is the class representing a frame of animation. For example, a typical 2D animation could be made
up of TextureRegions
and would be specified as:
Animation<TextureRegion> myAnimation = new Animation<TextureRegion>(...);
Modifier and Type | Class and Description |
---|---|
static class |
Animation.PlayMode
Defines possible playback modes for an
Animation . |
Constructor and Description |
---|
Animation(float frameDuration,
Array<? extends T> keyFrames)
Constructor, storing the frame duration and key frames.
|
Animation(float frameDuration,
Array<? extends T> keyFrames,
Animation.PlayMode playMode)
Constructor, storing the frame duration and key frames.
|
Animation(float frameDuration,
T... keyFrames)
Constructor, storing the frame duration and key frames.
|
Modifier and Type | Method and Description |
---|---|
float |
getAnimationDuration() |
float |
getFrameDuration() |
T |
getKeyFrame(float stateTime)
Returns a frame based on the so called state time.
|
T |
getKeyFrame(float stateTime,
boolean looping)
Returns a frame based on the so called state time.
|
int |
getKeyFrameIndex(float stateTime)
Returns the current frame number.
|
T[] |
getKeyFrames()
Returns the keyframes[] array where all the frames of the animation are stored.
|
Animation.PlayMode |
getPlayMode()
Returns the animation play mode.
|
boolean |
isAnimationFinished(float stateTime)
Whether the animation would be finished if played without looping (PlayMode#NORMAL), given the state time.
|
void |
setFrameDuration(float frameDuration)
Sets duration a frame will be displayed.
|
void |
setPlayMode(Animation.PlayMode playMode)
Sets the animation play mode.
|
public Animation(float frameDuration, Array<? extends T> keyFrames)
frameDuration
- the time between frames in seconds.keyFrames
- the objects representing the frames. If this Array is type-aware, getKeyFrames()
can return the
correct type of array. Otherwise, it returns an Object[].public Animation(float frameDuration, Array<? extends T> keyFrames, Animation.PlayMode playMode)
frameDuration
- the time between frames in seconds.keyFrames
- the objects representing the frames. If this Array is type-aware, getKeyFrames()
can
return the correct type of array. Otherwise, it returns an Object[].public Animation(float frameDuration, T... keyFrames)
frameDuration
- the time between frames in seconds.keyFrames
- the objects representing the frames.public T getKeyFrame(float stateTime, boolean looping)
stateTime
- the time spent in the state represented by this animation.looping
- whether the animation is looping or not.public T getKeyFrame(float stateTime)
setPlayMode(PlayMode)
method.stateTime
- public int getKeyFrameIndex(float stateTime)
stateTime
- public T[] getKeyFrames()
public Animation.PlayMode getPlayMode()
public void setPlayMode(Animation.PlayMode playMode)
playMode
- The animation Animation.PlayMode
to use.public boolean isAnimationFinished(float stateTime)
stateTime
- public void setFrameDuration(float frameDuration)
frameDuration
- in secondspublic float getFrameDuration()
public float getAnimationDuration()
Copyright © 2017. All rights reserved.