# Class AnimatedSprite

java.lang.Object
com.codename1.gaming.Sprite
com.codename1.gaming.AnimatedSprite

All Implemented Interfaces:
  `PhysicsLinkable`

public class AnimatedSprite extends Sprite

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.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AnimatedSprite(SpriteSheet sheet, int[] frameIndices, double secondsPerFrame)`
  Creates an animated sprite from frames pulled out of a `SpriteSheet`.
  `AnimatedSprite(Image[] frames, double secondsPerFrame)`
  Creates an animated sprite from an explicit array of frames.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `getCurrentFrame()`
  The index of the frame currently being shown.
  `int`
  `getFrameCount()`
  `double`
  `getFrameDuration()`
  `boolean`
  `isLooping()`
  `boolean`
  `isPlaying()`
  `protected void`
  `onUpdate(double deltaSeconds)`
  Per frame update hook.
  `void`
  `pause()`
  Pauses playback, keeping the current frame.
  `void`
  `play()`
  Starts (or resumes) playback.
  `void`
  `setCurrentFrame(int index)`
  Jumps to the given frame index.
  `void`
  `setFrameDuration(double secondsPerFrame)`
  `void`
  `setLooping(boolean looping)`
  `void`
  `stop()`
  Stops playback and rewinds to the first frame.

  ### Methods inherited from class Sprite

  `getAlpha, getAnchorX, getAnchorY, getBounds, getColor, getImage, getRenderHeight, getRenderWidth, getRotation, getScaleX, getScaleY, getUserData, getX, getY, getZOrder, intersects, isVisible, setAlpha, setAnchor, setColor, setImage, setPhysicsPosition, setPhysicsRotation, setPosition, setRotation, setScale, setScale, setSize, setUserData, setVisible, setX, setY, setZOrder`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AnimatedSprite

    public AnimatedSprite(Image[] frames, double secondsPerFrame)

    Creates an animated sprite from an explicit array of frames.

    ###### Parameters

    - `frames`: the frame images, played in order

    - `secondsPerFrame`: 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`: the source sprite sheet

    - `frameIndices`: the linear frame indices to play, in order

    - `secondsPerFrame`: how long each frame is shown, in seconds

- ## Method Details

  - ### onUpdate

    protected void onUpdate(double deltaSeconds)
    Description copied from class: `Sprite`
    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.
    Overrides:
      `onUpdate` in class `Sprite`

  - ### 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()