Interface Sprite

All Known Implementing Classes:
AnimatedSprite, CompositeSprite, EmptySprite, FlippedSprite, ImageSprite, SequenceSprite, TextSprite

public interface Sprite
A sprite to be displayed on the screen. Note that a sprite contains no state information, i.e. its just the image and not the location. This allows us to use a single sprite in lots of different places without having to store multiple copies of the image.
  • 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.
    default boolean
    Check whether the sprite won't change between draws.
  • Method Details

    • createRegion

      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.
      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

      void draw(Graphics g, int x, int y)
      Draw the sprite onto the graphics context provided.
      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

      void draw(Graphics g, int destx, int desty, int x, int y, int w, int h)
      Draws the image.
      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

      int getHeight()
      Get the height of the drawn sprite.
      Returns:
      The height in pixels of this sprite
    • getReference

      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.
      Returns:
      The reference identifier, or null if not referencable.
    • getWidth

      int getWidth()
      Get the width of the drawn sprite.
      Returns:
      The width in pixels of this sprite
    • isConstant

      default boolean isConstant()
      Check whether the sprite won't change between draws.
      Returns:
      true if different draws of the sprite always have the same result.