public class AnimatedSprite
ImplementsPhysicsLinkable
A Sprite that cycles through a sequence of frames over time.
The animation advances in #onUpdate(double), so adding it to a Scene whose
Scene#update(double) is called every frame (or calling #onUpdate(double)
directly) drives playback. By default it loops; set #setLooping(boolean) to
false to stop on the last frame.
Constructors
public AnimatedSprite(Image[] frames, double secondsPerFrame) | Creates an animated sprite from an explicit array of frames. |
public AnimatedSprite(SpriteSheet sheet, int[] frameIndices, double secondsPerFrame) | Creates an animated sprite from frames pulled out of a SpriteSheet. |
Methods
protected void onUpdate(double deltaSeconds) | Per frame update hook. |
public void play() | Starts (or resumes) playback. |
public void pause() | Pauses playback, keeping the current frame. |
public void stop() | Stops playback and rewinds to the first frame. |
public boolean isPlaying() | |
public boolean isLooping() | |
public void setLooping(boolean looping) | |
public double getFrameDuration() | |
public void setFrameDuration(double secondsPerFrame) | |
public int getCurrentFrame() | The index of the frame currently being shown. |
public void setCurrentFrame(int index) | Jumps to the given frame index. |
public int getFrameCount() |
Inherited methods
From Sprite
getRenderWidth, getRenderHeight, getBounds, intersects, setPhysicsPosition, setPhysicsRotation, getImage, setImage, getX, getY, setX, setY, setPosition, getZ, setZ, setPosition, getRotation, setRotation, getScaleX, getScaleY, setScale, setScale, setSize, getColor, setColor, getAlpha, setAlpha, getAnchorX, getAnchorY, setAnchor, isVisible, setVisible, getZOrder, setZOrder, getUserData, setUserData, getParallaxX, getParallaxY, setParallax
Constructor details
AnimatedSprite
public AnimatedSprite(Image[] frames, double secondsPerFrame)Parameters
framesImage[]- the frame images, played in order
secondsPerFramedouble- how long each frame is shown, in seconds
AnimatedSprite
public AnimatedSprite(SpriteSheet sheet, int[] frameIndices, double secondsPerFrame)SpriteSheet.Parameters
sheetSpriteSheet- the source sprite sheet
frameIndicesint[]- the linear frame indices to play, in order
secondsPerFramedouble- how long each frame is shown, in seconds
Method details
onUpdate
protected void onUpdate(double deltaSeconds)AnimatedSprite override it to advance over time. Scene#update(double)
invokes this for every sprite it contains.play
public void play()pause
public void pause()stop
public void stop()isPlaying
public boolean isPlaying()isLooping
public boolean isLooping()setLooping
public void setLooping(boolean looping)getFrameDuration
public double getFrameDuration()setFrameDuration
public void setFrameDuration(double secondsPerFrame)getCurrentFrame
public int getCurrentFrame()setCurrentFrame
public void setCurrentFrame(int index)getFrameCount
public int getFrameCount()