public class Animation extends java.lang.Object implements IUpdateable, ILaunchable
Animation
class keeps track of the current keyframe which is used to animate a visual element.
It iterates over all defined keyframes with respect to their duration and provides information
for the related AnimationController
which keyframe should currently be rendered.IAnimationController.getCurrent()
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_FRAME_DURATION
The default frame duration in milliseconds.
|
Constructor and Description |
---|
Animation(Spritesheet spritesheet,
boolean loop,
boolean randomizeStart,
int... keyFrameDurations)
Initializes a new instance of the
Animation class. |
Animation(Spritesheet spritesheet,
boolean loop,
int... keyFrameDurations)
Initializes a new instance of the
Animation class. |
Animation(java.lang.String spriteSheetName,
boolean loop,
boolean randomizeStart,
int... keyFrameDurations)
Initializes a new instance of the
Animation class. |
Animation(java.lang.String name,
Spritesheet spritesheet,
boolean loop,
boolean randomizeStart,
int... keyFrameDurations)
Initializes a new instance of the
Animation class. |
Animation(java.lang.String name,
Spritesheet spritesheet,
boolean loop,
int... keyFrameDurations)
Initializes a new instance of the
Animation class. |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getName()
Gets the name of this animation.
|
Spritesheet |
getSpritesheet() |
int |
getTotalDuration()
Gets to aggregated duration of all
KeyFrame s in this animation. |
boolean |
isLooping()
Gets a value indicating whether this animation intended to loop.
|
boolean |
isPaused()
Gets a value indicating whether this animation is currently paused.
|
boolean |
isPlaying()
Gets a value indicating whether this animation is currently playing.
|
void |
pause()
Pauses the playback of this animation.
|
void |
restart()
Restarts this animation at its first frame.
|
void |
setDurationForAllKeyFrames(int frameDuration)
Sets the frame duration for all keyframes in this animation to the
specified value.
|
void |
setKeyFrameDurations(int... keyFrameDurations)
Sets the specified durations for the keyframes at the index of the defined arguments.
|
void |
start()
Starts the operation of this instance.
|
void |
terminate()
Terminates the operation of this instance.
|
void |
unpause()
Un-pauses the playback of this animation.
|
void |
update()
This method is called by the game loop on all objects that are attached to the loop.
|
public static final int DEFAULT_FRAME_DURATION
public Animation(java.lang.String spriteSheetName, boolean loop, boolean randomizeStart, int... keyFrameDurations)
Animation
class.spriteSheetName
- The name of the spritesheet used by this animation.loop
- A flag indicating whether the animation should be looped or played only once.randomizeStart
- A flag indicating whether this animation should choose a random keyframe to start.keyFrameDurations
- The duration of each keyframe.public Animation(Spritesheet spritesheet, boolean loop, boolean randomizeStart, int... keyFrameDurations)
Animation
class.spritesheet
- The spritesheet used by this animation.loop
- A flag indicating whether the animation should be looped or played only once.randomizeStart
- A flag indicating whether this animation should choose a random keyframe to start.keyFrameDurations
- The duration of each keyframe.public Animation(Spritesheet spritesheet, boolean loop, int... keyFrameDurations)
Animation
class.spritesheet
- The spritesheet used by this animation.loop
- A flag indicating whether the animation should be looped or played only once.keyFrameDurations
- The duration of each keyframe.public Animation(java.lang.String name, Spritesheet spritesheet, boolean loop, boolean randomizeStart, int... keyFrameDurations)
Animation
class.name
- The name of this animation.spritesheet
- The spritesheet used by this animation.loop
- A flag indicating whether the animation should be looped or played only once.randomizeStart
- A flag indicating whether this animation should choose a random keyframe to start.keyFrameDurations
- The duration of each keyframe.public Animation(java.lang.String name, Spritesheet spritesheet, boolean loop, int... keyFrameDurations)
Animation
class.name
- The name of this animation.spritesheet
- The spritesheet used by this animation.loop
- A flag indicating whether the animation should be looped or played only once.keyFrameDurations
- The duration of each keyframe.public int getTotalDuration()
KeyFrame
s in this animation.public java.lang.String getName()
public Spritesheet getSpritesheet()
public boolean isLooping()
public boolean isPaused()
public boolean isPlaying()
public void pause()
isPaused()
,
unpause()
public void unpause()
isPaused()
,
pause()
public void setDurationForAllKeyFrames(int frameDuration)
frameDuration
- The frameduration for all keyframes.public void setKeyFrameDurations(int... keyFrameDurations)
e.g.: If this animation defines 5 keyframes, the caller of this method can provide 5 individual durations for each keyframe.
keyFrameDurations
- The durations to be set on the keyframes of this animation.public void start()
ILaunchable
start
in interface ILaunchable
public void restart()
public void terminate()
ILaunchable
terminate
in interface ILaunchable
public void update()
IUpdateable
ClientConfiguration
.update
in interface IUpdateable
ClientConfiguration.setMaxFps(int)