Package doodlepad

Class Sprite


public class Sprite extends Shape
A class that loads a sprite sheet image from a file and animates it on a Pad
  • Constructor Details

    • Sprite

      public Sprite(String path, double x, double y, int frameWidth, int nFrames)
      Constructor for objects of class Sprite
      Parameters:
      path - Path to sprite sheet image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      frameWidth - The width of a single frame in the sprite sheet image.
      nFrames - The number of adjacent frames in the entire sprite sheet image.
    • Sprite

      public Sprite(String path, double x, double y, int frameWidth, int nFrames, Pad pad)
      Constructor for objects of class Sprite
      Parameters:
      path - Path to sprite sheet image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      frameWidth - The width of a single frame in the sprite sheet image.
      nFrames - The number of adjacent frames in the entire sprite sheet image.
      pad - The Pad to which the Sprite will be added.
    • Sprite

      public Sprite(String path, double x, double y, int frameWidth, int nFrames, Layer layer)
      Constructor for objects of class Sprite
      Parameters:
      path - Path to sprite sheet image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      frameWidth - The width of a single frame in the sprite sheet image.
      nFrames - The number of adjacent frames in the entire sprite sheet image.
      layer - The Layer object to which the Image will be added, or null if not to add to a Layer.
    • Sprite

      public Sprite(String path, double x, double y, double frameWidth, int nFrames, int targetWidth, int targetHeight)
      Constructor for objects of class Sprite
      Parameters:
      path - Path to image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      frameWidth - The width of a single frame in the sprite sheet image.
      nFrames - The number of adjacent frames in the entire sprite sheet image.
      targetWidth - The width with which to draw the sprite.
      targetHeight - The height with which to draw the sprite.
    • Sprite

      public Sprite(String path, double x, double y, double frameWidth, int nFrames, double targetWidth, double targetHeight, Layer layer)
      Constructor for objects of class Sprite
      Parameters:
      path - Path to image file.
      x - The x-coordinate of the image upper left corner.
      y - The y-coordinate of the image upper left corner.
      frameWidth - The width of a single frame in the sprite sheet image.
      nFrames - The number of adjacent frames in the entire sprite sheet image.
      targetWidth - The width with which to draw the sprite.
      targetHeight - The height with which to draw the sprite.
      layer - The Layer object to which the Sprite will be added, or null if not to add to a Pad.
  • Method Details

    • setText

      public void setText(String text)
      A no-op to prevent setting text for this Shape.
      Overrides:
      setText in class Shape
      Parameters:
      text - The internal text as a String
    • toString

      public String toString()
      Generate a representation of the Sprite object.
      Overrides:
      toString in class Shape
      Returns:
      String representation
    • advance

      public void advance()
      Advance the sprite frame and repaint
    • draw

      public void draw(Graphics2D g)
      Draw the current sprite frame
      Specified by:
      draw in class Shape
      Parameters:
      g - The Graphics2D object on which to draw the sprite frame