Class Sprite

java.lang.Object
model.Sprite

public class Sprite extends Object
A sprite that is used by an Entity as the Entities visual representation (ie what you see 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.
  • Constructor Details

    • Sprite

      public Sprite(String ref, Image image)
      Create a new sprite based on an image
      Parameters:
      image - The image that is this sprite
  • Method Details

    • getWidth

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

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

      public 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
    • getRef

      public String getRef()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object