APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.graphics.g2d

public Class Animation<T>

extends Object
Class Inheritance
Imports
com.badlogic.gdx.math.MathUtils, com.badlogic.gdx.utils.Array, java.util.Arrays

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>(...);

Author
mzechner

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Animation.PlayMode

Defines possible playback modes for an Animation.

Field Summary

Modifier and TypeField and Description
private float
private float
pack-priv T[]
keyFrames

Length must not be modified without updating animationDuration.

private int
private float
private Animation.PlayMode

Constructor Summary

AccessConstructor and Description
public
Animation(float
the time between frames in seconds.
frameDuration
,
Array<? extends T>
the objects representing the frames. If this Array is type-aware, getKeyFrames() can return the correct type of array. Otherwise, it returns an Object[].
keyFrames
)

Constructor, storing the frame duration and key frames.

public
Animation(float
the time between frames in seconds.
frameDuration
,
Array<? extends T>
the objects representing the frames. If this Array is type-aware, getKeyFrames() can return the correct type of array. Otherwise, it returns an Object[].
keyFrames
,
Animation.PlayMode playMode)

Constructor, storing the frame duration and key frames.

public
Animation(float
the time between frames in seconds.
frameDuration
,
T...
the objects representing the frames.
keyFrames
)

Constructor, storing the frame duration and key frames.

Method Summary

Modifier and TypeMethod and Description
public float
getAnimationDuration()

Returns: the duration of the entire animation, number of frames times frame duration, in seconds

public float
getFrameDuration()

Returns: the duration of a frame in seconds

public T

Returns:

the frame of animation for the given state time.
getKeyFrame
(float
the time spent in the state represented by this animation.
stateTime
,
boolean
whether the animation is looping or not.
looping
)

Returns a frame based on the so called state time.

public T

Returns:

the frame of animation for the given state time.
getKeyFrame
(float stateTime)

Returns a frame based on the so called state time.

public int

Returns:

current frame number
getKeyFrameIndex
(float stateTime)

Returns the current frame number.

public T[]

Returns:

The keyframes[] field. This array is an Object[] if the animation was instantiated with an Array that was not type-aware.
getKeyFrames
()

Returns the keyframes[] array where all the frames of the animation are stored.

public Animation.PlayMode
getPlayMode()

Returns the animation play mode.

public boolean

Returns:

whether the animation is finished.
isAnimationFinished
(float stateTime)

Whether the animation would be finished if played without looping (PlayMode#NORMAL), given the state time.

public void
setFrameDuration(float
in seconds
frameDuration
)

Sets duration a frame will be displayed.

protected void
setKeyFrames(T... keyFrames)

public void
setPlayMode(Animation.PlayMode
The animation PlayMode to use.
playMode
)

Sets the animation play mode.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

animationDurationback to summary
private float animationDuration
frameDurationback to summary
private float frameDuration
keyFramesback to summary
pack-priv T[] keyFrames

Length must not be modified without updating animationDuration. See setKeyFrames(T[]).

lastFrameNumberback to summary
private int lastFrameNumber
lastStateTimeback to summary
private float lastStateTime
playModeback to summary
private Animation.PlayMode playMode

Constructor Detail

Animationback to summary
public Animation(float frameDuration, Array<? extends T> keyFrames)

Constructor, storing the frame duration and key frames.

Parameters
frameDuration:float

the time between frames in seconds.

keyFrames:Array<? extends T>

the objects representing the frames. If this Array is type-aware, getKeyFrames() can return the correct type of array. Otherwise, it returns an Object[].

Animationback to summary
public Animation(float frameDuration, Array<? extends T> keyFrames, Animation.PlayMode playMode)

Constructor, storing the frame duration and key frames.

Parameters
frameDuration:float

the time between frames in seconds.

keyFrames:Array<? extends T>

the objects representing the frames. If this Array is type-aware, getKeyFrames() can return the correct type of array. Otherwise, it returns an Object[].

Animationback to summary
public Animation(float frameDuration, T... keyFrames)

Constructor, storing the frame duration and key frames.

Parameters
frameDuration:float

the time between frames in seconds.

keyFrames:T[]

the objects representing the frames.

Method Detail

getAnimationDurationback to summary
public float getAnimationDuration()
Returns:float

the duration of the entire animation, number of frames times frame duration, in seconds

getFrameDurationback to summary
public float getFrameDuration()
Returns:float

the duration of a frame in seconds

getKeyFrameback to summary
public T getKeyFrame(float stateTime, boolean looping)

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:float

the time spent in the state represented by this animation.

looping:boolean

whether the animation is looping or not.

Returns:T

the frame of animation for the given state time.

getKeyFrameback to summary
public T getKeyFrame(float stateTime)

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 by setPlayMode(PlayMode) method.

Returns:T

the frame of animation for the given state time.

getKeyFrameIndexback to summary
public int getKeyFrameIndex(float stateTime)

Returns the current frame number.

Returns:int

current frame number

getKeyFramesback to summary
public T[] getKeyFrames()

Returns the keyframes[] array where all the frames of the animation are stored.

Returns:T[]

The keyframes[] field. This array is an Object[] if the animation was instantiated with an Array that was not type-aware.

getPlayModeback to summary
public Animation.PlayMode getPlayMode()

Returns the animation play mode.

isAnimationFinishedback to summary
public boolean isAnimationFinished(float stateTime)

Whether the animation would be finished if played without looping (PlayMode#NORMAL), given the state time.

Returns:boolean

whether the animation is finished.

setFrameDurationback to summary
public void setFrameDuration(float frameDuration)

Sets duration a frame will be displayed.

Parameters
frameDuration:float

in seconds

setKeyFramesback to summary
protected void setKeyFrames(T... keyFrames)
setPlayModeback to summary
public void setPlayMode(Animation.PlayMode playMode)

Sets the animation play mode.

Parameters
playMode:Animation.PlayMode

The animation PlayMode to use.

com.badlogic.gdx.graphics.g2d back to summary

public final Enum Animation.PlayMode

extends Enum<Animation.PlayMode>
Class Inheritance

Defines possible playback modes for an Animation.

Field Summary

Modifier and TypeField and Description
public static final Animation.PlayMode
public static final Animation.PlayMode
public static final Animation.PlayMode
public static final Animation.PlayMode
public static final Animation.PlayMode
public static final Animation.PlayMode

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Animation.PlayMode
public static Animation.PlayMode[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

LOOPback to summary
public static final Animation.PlayMode LOOP
LOOP_PINGPONGback to summary
public static final Animation.PlayMode LOOP_PINGPONG
LOOP_RANDOMback to summary
public static final Animation.PlayMode LOOP_RANDOM
LOOP_REVERSEDback to summary
public static final Animation.PlayMode LOOP_REVERSED
NORMALback to summary
public static final Animation.PlayMode NORMAL
REVERSEDback to summary
public static final Animation.PlayMode REVERSED

Constructor Detail

PlayModeback to summary
private PlayMode()

Method Detail

valueOfback to summary
public static Animation.PlayMode valueOf(String name)
valuesback to summary
public static Animation.PlayMode[] values()