Class SpriteAnimation
java.lang.Object
com.codingame.gameengine.module.entities.Entity<T>
com.codingame.gameengine.module.entities.BlendableEntity<T>
com.codingame.gameengine.module.entities.TextureBasedEntity<SpriteAnimation>
com.codingame.gameengine.module.entities.SpriteAnimation
- All Implemented Interfaces:
Mask
A
SpriteAnimation
is a graphical entity which displays a sequence of images. You can use this class to animate a sprite based on
milliseconds, rather than frame time.-
Nested Class Summary
Nested classes/interfaces inherited from class com.codingame.gameengine.module.entities.BlendableEntity
BlendableEntity.BlendMode
-
Method Summary
Modifier and TypeMethodDescriptionint
Returns the duration of the animation in milliseconds.String[]
Returns the names of the images used for this animation.boolean
isLoop()
Returns whether the animation should loop.boolean
Returns whether the animation is flagged to have the graphical counterpart play the animation or to pause it.pause()
Calls setPlaying(false);play()
Calls setPlaying(true);reset()
Reset the progress of the animationsetDuration
(int duration) Sets the duration of the animation in milliseconds.Sets the sequence of images for this animation.setLoop
(boolean loop) Sets whether the animation loops.setPlaying
(boolean playing) Plays or pause the animation.Methods inherited from class com.codingame.gameengine.module.entities.TextureBasedEntity
getAnchorX, getAnchorY, getTint, setAnchor, setAnchorX, setAnchorX, setAnchorY, setAnchorY, setTint, setTint
Methods inherited from class com.codingame.gameengine.module.entities.BlendableEntity
getBlendMode, setBlendMode
Methods inherited from class com.codingame.gameengine.module.entities.Entity
getAlpha, getId, getMask, getParent, getRotation, getScaleX, getScaleY, getSkewX, getSkewY, getX, getY, getZIndex, isVisible, requireValidAlpha, requireValidColor, self, set, set, setAlpha, setAlpha, setMask, setMask, setRotation, setRotation, setScale, setScale, setScaleX, setScaleX, setScaleY, setScaleY, setSkewX, setSkewX, setSkewY, setSkewY, setVisible, setX, setX, setY, setY, setZIndex
-
Method Details
-
isPlaying
public boolean isPlaying()Returns whether the animation is flagged to have the graphical counterpart play the animation or to pause it.Default is true.
- Returns:
- true if the animation is playing.
-
setPlaying
Plays or pause the animation.Default is playing (true).
- Parameters:
playing
- true to play animation, false to pause animation- Returns:
- this animation.
-
reset
Reset the progress of the animation- Returns:
- this animation.
-
play
Calls setPlaying(true);- Returns:
- this animation.
-
pause
Calls setPlaying(false);- Returns:
- this animation.
-
isLoop
public boolean isLoop()Returns whether the animation should loop.Default is false.
- Returns:
- true if the animation loops.
-
setLoop
Sets whether the animation loops. If false, the last image of the animation stays visible at the end.Default is false.
- Parameters:
loop
- true to make this animation loop.- Returns:
- this animation.
-
getDuration
public int getDuration()Returns the duration of the animation in milliseconds.Default is 1000.
- Returns:
- the duration of the animation in milliseconds.
-
setDuration
Sets the duration of the animation in milliseconds.Default is 1000.
- Parameters:
duration
- the duration of the animation in milliseconds.- Returns:
- this animation.
- Throws:
IllegalArgumentException
- if duration is negative.
-
setImages
Sets the sequence of images for this animation.- Parameters:
images
- the names of the images to use for this animation.- Returns:
- this animation.
- Throws:
IllegalArgumentException
- if images is empty.
-
getImages
Returns the names of the images used for this animation.- Returns:
- the names of the images used for this animation.
-