Class AnimatedSprite

java.lang.Object
games.stendhal.client.sprite.AnimatedSprite
All Implemented Interfaces:
Sprite
Direct Known Subclasses:
SequenceSprite

public class AnimatedSprite extends Object implements Sprite
This is a sprite that transparently animates itself when drawn.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int[]
    The [minimum] frame durations.
    protected Sprite[]
    The frame sprites.
    protected long
    The time of the last update.
    protected boolean
    Whether to loop after last frame.
    protected Sprite
    The current sprite.
  • Constructor Summary

    Constructors
    Constructor
    Description
    AnimatedSprite​(Sprite[] frames, int delay, boolean animating)
    Create an animated sprite from a set of frame sprites.
  • Method Summary

    Modifier and Type
    Method
    Description
    createRegion​(int x, int y, int width, int height, Object ref)
    Create a sub-region of this sprite.
    void
    draw​(Graphics g, int x, int y)
    Draw the sprite onto the graphics context provided.
    void
    draw​(Graphics g, int destx, int desty, int x, int y, int w, int h)
    Draws the image.
    int
    Get the height of the drawn sprite.
    Get the sprite reference.
    int
    Get the width of the drawn sprite.
    void
    reset​(int index)
    Reset the animation back to specified frame, and reset the next frame time.
    void
    Start the sprite animating.
    void
    Stop the sprite animating.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface games.stendhal.client.sprite.Sprite

    isConstant
  • Field Details

    • delays

      protected int[] delays
      The [minimum] frame durations.
    • frames

      protected Sprite[] frames
      The frame sprites.
    • lastUpdate

      protected long lastUpdate
      The time of the last update.
    • loop

      protected boolean loop
      Whether to loop after last frame.
    • sprite

      protected Sprite sprite
      The current sprite.
  • Constructor Details

    • AnimatedSprite

      public AnimatedSprite(Sprite[] frames, int delay, boolean animating)
      Create an animated sprite from a set of frame sprites. NOTE: The array of frames passed is not copied, and must not be modified while this instance exists (unless you are sure you know what you are doing).
      Parameters:
      frames - The frames to animate.
      delay - The minimum delay between frames (in ms).
      animating - If animation is enabled.
      Throws:
      IllegalArgumentException - If less than one frame is given, or the delay is < 0.
  • Method Details

    • reset

      public void reset(int index)
      Reset the animation back to specified frame, and reset the next frame time.
      Parameters:
      index - the default index
    • start

      public void start()
      Start the sprite animating.
      See Also:
      stop()
    • stop

      public void stop()
      Stop the sprite animating. This does not change the current frame.
      See Also:
      start()
    • createRegion

      public Sprite createRegion(int x, int y, int width, int height, Object ref)
      Create a sub-region of this sprite. NOTE: This does not use caching.
      Specified by:
      createRegion in interface Sprite
      Parameters:
      x - The starting X coordinate.
      y - The starting Y coordinate.
      width - The region width.
      height - The region height.
      ref - The sprite reference.
      Returns:
      A new sprite.
    • draw

      public void draw(Graphics g, int x, int y)
      Draw the sprite onto the graphics context provided.
      Specified by:
      draw in interface Sprite
      Parameters:
      g - The graphics context on which to draw the sprite
      x - The x location at which to draw the sprite
      y - The y location at which to draw the sprite
    • draw

      public void draw(Graphics g, int destx, int desty, int x, int y, int w, int h)
      Draws the image.
      Specified by:
      draw in interface Sprite
      Parameters:
      g - the graphics context where to draw to
      destx - destination x
      desty - destination y
      x - the source x
      y - the source y
      w - the width
      h - the height
    • getHeight

      public int getHeight()
      Get the height of the drawn sprite.
      Specified by:
      getHeight in interface Sprite
      Returns:
      The height in pixels of this sprite.
    • getReference

      public Object getReference()
      Get the sprite reference. This identifier is an externally opaque object that implements equals() and hashCode() to uniquely/repeatably reference a keyed sprite.
      Specified by:
      getReference in interface Sprite
      Returns:
      The reference identifier, or null if not referencable.
    • getWidth

      public int getWidth()
      Get the width of the drawn sprite.
      Specified by:
      getWidth in interface Sprite
      Returns:
      The width in pixels of this sprite.