Record Class Sprite

java.lang.Object
java.lang.Record
cit244.api.image.Sprite
Record Components:
image - source image
x - left edge of the region, in source-image pixels
y - top edge of the region, in source-image pixels
width - region width in pixels
height - region height in pixels

public record Sprite(Image image, int x, int y, int width, int height) extends Record
A rectangular region of an Image, measured in source-image pixels.

A sprite does not store a screen position. Use at(double, double) to create drawing instructions for it.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Sprite(Image image, int x, int y, int width, int height)
    Checks that the selected region fits inside the source image.
  • Method Summary

    Modifier and Type
    Method
    Description
    at(double x, double y)
    Creates drawing instructions with a top-left anchor and native scale.
    at(Vec2 position)
    Creates drawing instructions at the given screen position.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    int
    Returns the value of the height record component.
    Returns the value of the image record component.
    final String
    Returns a string representation of this record class.
    int
    Returns the value of the width record component.
    int
    x()
    Returns the value of the x record component.
    int
    y()
    Returns the value of the y record component.

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Sprite

      public Sprite(Image image, int x, int y, int width, int height)
      Checks that the selected region fits inside the source image.
      Throws:
      NullPointerException - if image is null
      IllegalArgumentException - if the region is empty or outside the image
  • Method Details

    • at

      public SpriteDraw at(double x, double y)
      Creates drawing instructions with a top-left anchor and native scale.
      Parameters:
      x - screen x-coordinate
      y - screen y-coordinate
      Returns:
      drawing instructions for this sprite
    • at

      public SpriteDraw at(Vec2 position)
      Creates drawing instructions at the given screen position.
      Parameters:
      position - location of the default top-left anchor
      Returns:
      drawing instructions for this sprite
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • image

      public Image image()
      Returns the value of the image record component.
      Returns:
      the value of the image record component
    • x

      public int x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

      public int y()
      Returns the value of the y record component.
      Returns:
      the value of the y record component
    • width

      public int width()
      Returns the value of the width record component.
      Returns:
      the value of the width record component
    • height

      public int height()
      Returns the value of the height record component.
      Returns:
      the value of the height record component