Class Animation
- java.lang.Object
-
- sk.tuke.kpi.gamelib.graphics.Animation
-
- All Implemented Interfaces:
Drawable<com.badlogic.gdx.graphics.g2d.Batch>
public final class Animation extends java.lang.Object implements Drawable<com.badlogic.gdx.graphics.g2d.Batch>
Animated or static graphical representation of game objects (actors).Loads a sprite sheet from
resource
image file. Constructor parametersspriteWidth
andspriteHeight
should specify sprite dimensions. If the resource file dimensions are larger, they must be multiples of sprite's dimensions. The resource image will be automatically split into frames.Single-frame animations can be created with constructor with single parameter, with sprite dimensions automatically set to the dimensions of the resource.
For animated resources (multiple frames),
frame duration
defines how long one frame is displayed, andplay mode
defines how the next frame to show is selected (see enumAnimation.PlayMode
for options).Additional parameters allow to define:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Animation.PlayMode
Play mode defines a method for selecting next animation frame.
-
Constructor Summary
Constructors Constructor Description Animation(@NotNull java.lang.String resource)
Animation(@NotNull java.lang.String resource, int spriteWidth, int spriteHeight)
Animation(@NotNull java.lang.String resource, int spriteWidth, int spriteHeight, float frameDuration)
Animation(@NotNull java.lang.String resource, int spriteWidth, int spriteHeight, float frameDuration, @NotNull Animation.PlayMode playmode)
Animation(@NotNull java.lang.String resource, int spriteWidth, int spriteHeight, float frameDuration, @NotNull Animation.PlayMode playmode, @NotNull Color tint)
Animation(@NotNull java.lang.String resource, int spriteWidth, int spriteHeight, float frameDuration, @NotNull Animation.PlayMode playmode, @NotNull Color tint, float scale)
Animation(@NotNull java.lang.String resource, int spriteWidth, int spriteHeight, float frameDuration, @NotNull Animation.PlayMode playMode, @NotNull Color tint, float scale, float rotation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
draw(@NotNull com.badlogic.gdx.graphics.g2d.Batch batch, float posX, float posY)
void
draw(@NotNull com.badlogic.gdx.graphics.g2d.Batch batch, float posX, float posY, float deltaTime)
Draws the animation to the given batch at [posX, posY] coordinates.float
getAlpha()
Alpha transparency applied to the animation.int
getCurrentFrameIndex()
Index of currently shown animation frame.int
getFrameCount()
Count of animation frames.float
getFrameDuration()
Duration of a single animation frame.int
getHeight()
Height of the animation object (sprite height).@NotNull Animation.PlayMode
getPlayMode()
Playing mode of the animation, one ofAnimation.PlayMode
enum values.@NotNull java.lang.String
getResource()
float
getRotation()
Rotation of the animation in degrees.float
getScale()
Scale of the animation, relative to the sprite image size.@NotNull Color
getTint()
A colored tint applied over animation to change its appearance.int
getWidth()
Width of the animation object (sprite width).void
pause()
Pauses the animation, causing it to keep rendering the current frame.void
play()
Starts to play or continues to play the animation according to theplay mode
.void
resetToFirstFrame()
Resets the animation to its first frame.void
setAlpha(float alpha)
void
setFrameDuration(float frameDuration)
void
setPlayMode(@NotNull Animation.PlayMode playMode)
void
setRotation(float rotation)
void
setScale(float scale)
void
setTint(@NotNull Color tint)
void
stop()
Stops playing animation and shows its first frame.java.lang.String
toString()
-
-
-
Constructor Detail
-
Animation
public Animation(@NotNull @NotNull java.lang.String resource)
-
Animation
public Animation(@NotNull @NotNull java.lang.String resource, int spriteWidth, int spriteHeight)
-
Animation
public Animation(@NotNull @NotNull java.lang.String resource, int spriteWidth, int spriteHeight, float frameDuration)
-
Animation
public Animation(@NotNull @NotNull java.lang.String resource, int spriteWidth, int spriteHeight, float frameDuration, @NotNull @NotNull Animation.PlayMode playmode)
-
Animation
public Animation(@NotNull @NotNull java.lang.String resource, int spriteWidth, int spriteHeight, float frameDuration, @NotNull @NotNull Animation.PlayMode playmode, @NotNull @NotNull Color tint)
-
Animation
public Animation(@NotNull @NotNull java.lang.String resource, int spriteWidth, int spriteHeight, float frameDuration, @NotNull @NotNull Animation.PlayMode playmode, @NotNull @NotNull Color tint, float scale)
-
Animation
public Animation(@NotNull @NotNull java.lang.String resource, int spriteWidth, int spriteHeight, float frameDuration, @NotNull @NotNull Animation.PlayMode playMode, @NotNull @NotNull Color tint, float scale, float rotation)
-
-
Method Detail
-
getResource
@NotNull public @NotNull java.lang.String getResource()
-
getWidth
public int getWidth()
Width of the animation object (sprite width).
-
getHeight
public int getHeight()
Height of the animation object (sprite height).
-
getPlayMode
@NotNull public @NotNull Animation.PlayMode getPlayMode()
Playing mode of the animation, one ofAnimation.PlayMode
enum values.
-
setPlayMode
public void setPlayMode(@NotNull @NotNull Animation.PlayMode playMode)
-
getTint
@NotNull public @NotNull Color getTint()
A colored tint applied over animation to change its appearance.
-
setTint
public void setTint(@NotNull @NotNull Color tint)
-
getScale
public float getScale()
Scale of the animation, relative to the sprite image size.
-
setScale
public void setScale(float scale)
-
getRotation
public float getRotation()
Rotation of the animation in degrees.
-
setRotation
public void setRotation(float rotation)
-
getAlpha
public float getAlpha()
Alpha transparency applied to the animation.
-
setAlpha
public void setAlpha(float alpha)
-
getFrameDuration
public float getFrameDuration()
Duration of a single animation frame.
-
setFrameDuration
public void setFrameDuration(float frameDuration)
-
getFrameCount
public int getFrameCount()
Count of animation frames.
-
getCurrentFrameIndex
public int getCurrentFrameIndex()
Index of currently shown animation frame.
-
play
public void play()
Starts to play or continues to play the animation according to theplay mode
.
-
pause
public void pause()
Pauses the animation, causing it to keep rendering the current frame.
-
resetToFirstFrame
public void resetToFirstFrame()
Resets the animation to its first frame. The animation will continue to play, if it was not in a stopped state.
-
stop
public void stop()
Stops playing animation and shows its first frame.A convenience method combining the
pause()
andresetToFirstFrame()
methods.
-
draw
public void draw(@NotNull @NotNull com.badlogic.gdx.graphics.g2d.Batch batch, float posX, float posY)
-
draw
public void draw(@NotNull @NotNull com.badlogic.gdx.graphics.g2d.Batch batch, float posX, float posY, float deltaTime)
Draws the animation to the given batch at [posX, posY] coordinates.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-