public class AnimatedSprite

  1. Object
  2. Sprite
  3. 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

Constructor details

AnimatedSprite

public AnimatedSprite(Image[] frames, double secondsPerFrame)
Creates an animated sprite from an explicit array of frames.

Parameters

frames Image[]
the frame images, played in order
secondsPerFrame double
how long each frame is shown, in seconds

AnimatedSprite

public AnimatedSprite(SpriteSheet sheet, int[] frameIndices, double secondsPerFrame)
Creates an animated sprite from frames pulled out of a SpriteSheet.

Parameters

sheet SpriteSheet
the source sprite sheet
frameIndices int[]
the linear frame indices to play, in order
secondsPerFrame double
how long each frame is shown, in seconds

Method details

onUpdate

protected void onUpdate(double deltaSeconds)
Per frame update hook. The default implementation does nothing; subclasses such as AnimatedSprite override it to advance over time. Scene#update(double) invokes this for every sprite it contains.

play

public void play()
Starts (or resumes) playback.

pause

public void pause()
Pauses playback, keeping the current frame.

stop

public void stop()
Stops playback and rewinds to the first frame.

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()
The index of the frame currently being shown.

setCurrentFrame

public void setCurrentFrame(int index)
Jumps to the given frame index.

getFrameCount

public int getFrameCount()