Package arc.graphics.g2d
Class Animation<T>
java.lang.Object
arc.graphics.g2d.Animation<T>
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>(...);
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionConstructor, storing the frame duration and key frames.Animation
(float frameDuration, Seq<? extends T> keyFrames, Animation.PlayMode playMode) Constructor, storing the frame duration and key frames.Constructor, storing the frame duration and key frames. -
Method Summary
Modifier and TypeMethodDescriptionfloat
float
getKeyFrame
(float stateTime) Returns a frame based on the so called state time.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[]
Returns the keyframes[] array where all the frames of the animation are stored.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.protected void
setKeyFrames
(T... keyFrames) void
setPlayMode
(Animation.PlayMode playMode) Sets the animation play mode.
-
Constructor Details
-
Animation
Constructor, storing the frame duration and key frames.- Parameters:
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[].
-
Animation
Constructor, storing the frame duration and key frames.- Parameters:
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[].
-
Animation
Constructor, storing the frame duration and key frames.- Parameters:
frameDuration
- the time between frames in seconds.keyFrames
- the objects representing the frames.
-
-
Method Details
-
getKeyFrame
Returns a frame based on the so called state time. This is the amount of seconds an object has spent in the state this Animation instance represents, e.g. running, jumping and so on. The mode specifies whether the animation is looping or not.- Parameters:
stateTime
- the time spent in the state represented by this animation.looping
- whether the animation is looping or not.- Returns:
- the frame of animation for the given state time.
-
getKeyFrame
Returns a frame based on the so called state time. This is the amount of seconds an object has spent in the state this Animation instance represents, e.g. running, jumping and so on using the mode specified bysetPlayMode(PlayMode)
method.- Returns:
- the frame of animation for the given state time.
-
getKeyFrameIndex
public int getKeyFrameIndex(float stateTime) Returns the current frame number.- Returns:
- current frame number
-
getKeyFrames
Returns the keyframes[] array where all the frames of the animation are stored.- Returns:
- The keyframes[] field. This array is an Object[] if the animation was instantiated with an Array that was not type-aware.
-
setKeyFrames
-
getPlayMode
Returns the animation play mode. -
setPlayMode
Sets the animation play mode.- Parameters:
playMode
- The animationAnimation.PlayMode
to use.
-
isAnimationFinished
public boolean isAnimationFinished(float stateTime) Whether the animation would be finished if played without looping (PlayMode#NORMAL), given the state time.- Returns:
- whether the animation is finished.
-
getFrameDuration
public float getFrameDuration()- Returns:
- the duration of a frame in seconds
-
setFrameDuration
public void setFrameDuration(float frameDuration) Sets duration a frame will be displayed.- Parameters:
frameDuration
- in seconds
-
getAnimationDuration
public float getAnimationDuration()- Returns:
- the duration of the entire animation, number of frames times frame duration, in seconds
-