Record Class SpriteDraw

java.lang.Object
java.lang.Record
cit244.api.image.SpriteDraw
Record Components:
sprite - the source sprite
x - horizontal position of the anchor, in pixels
y - vertical position of the anchor, in pixels
anchorX - horizontal anchor fraction (0 = left, 1 = right)
anchorY - vertical anchor fraction (0 = top, 1 = bottom)
scale - uniform scale factor (1 = original size)
rotation - clockwise angle in radians, in screen coordinates
flippedX - whether the sprite is mirrored horizontally
flippedY - whether the sprite is mirrored vertically
tint - optional color multiplier; null uses the current tint

public record SpriteDraw(Sprite sprite, double x, double y, double anchorX, double anchorY, double scale, double rotation, boolean flippedX, boolean flippedY, Color tint) extends Record
Immutable instructions for drawing a Sprite at a particular position.

The anchor specifies which point of the sprite is placed at (x, y). Scale, rotation, and flips act around that anchor. Each modifier returns a new SpriteDraw; the original remains unchanged.


 g.sprite(sprite.at(position)
                .bottomCenter()
                .scale(3)
                .flipX(facingLeft));
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    SpriteDraw(Sprite sprite, double x, double y, double anchorX, double anchorY, double scale, double rotation, boolean flippedX, boolean flippedY, Color tint)
    Requires a sprite, finite coordinates and transforms, and nonnegative scale.
  • Method Summary

    Modifier and Type
    Method
    Description
    anchor(double x, double y)
    Changes the anchor point, using fractions of the sprite's dimensions.
    double
    Returns the value of the anchorX record component.
    double
    Returns the value of the anchorY record component.
    at(double x, double y)
    Returns drawing instructions at the given position.
    at(Vec2 position)
    Returns drawing instructions at the given position.
    Sets the anchor to the center of the sprite's bottom edge.
    Sets the anchor to the sprite's center.
    final boolean
    Indicates whether some other object is "equal to" this one.
    boolean
    Returns the value of the flippedX record component.
    boolean
    Returns the value of the flippedY record component.
    Enables horizontal mirroring.
    flipX(boolean enabled)
    Enables or disables horizontal mirroring.
    Enables vertical mirroring.
    flipY(boolean enabled)
    Enables or disables vertical mirroring.
    final int
    Returns a hash code value for this object.
    static SpriteDraw
    of(Sprite sprite, double x, double y)
    Creates drawing instructions at native scale with a top-left anchor, no rotation, no flipping, and no local tint.
    rotate(double radians)
    Sets clockwise rotation about the anchor.
    double
    Returns the value of the rotation record component.
    double
    Returns the value of the scale record component.
    scale(double factor)
    Sets the uniform drawing scale.
    scaledBy(double factor)
    Multiplies the current scale by a factor.
    Returns the value of the sprite record component.
    Returns the value of the tint record component.
    tint(Color color)
    Sets a local image tint, including alpha.
    final String
    Returns a string representation of this record class.
    translate(double dx, double dy)
    Moves the anchor by a displacement in screen coordinates, not along the sprite's rotated local axes.
    translate(Vec2 offset)
    Moves the anchor by a displacement in screen coordinates.
    double
    x()
    Returns the value of the x record component.
    double
    y()
    Returns the value of the y record component.

    Methods inherited from class java.lang.Object

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

    • SpriteDraw

      public SpriteDraw(Sprite sprite, double x, double y, double anchorX, double anchorY, double scale, double rotation, boolean flippedX, boolean flippedY, Color tint)
      Requires a sprite, finite coordinates and transforms, and nonnegative scale.

      This constructor is NOT intended to be used directly.

      Throws:
      NullPointerException - if sprite is null
      IllegalArgumentException - if any numeric value is non-finite or scale is negative
  • Method Details

    • of

      public static SpriteDraw of(Sprite sprite, double x, double y)
      Creates drawing instructions at native scale with a top-left anchor, no rotation, no flipping, and no local tint.
      Parameters:
      sprite - sprite to draw
      x - horizontal screen position
      y - vertical screen position
      Returns:
      default drawing instructions
    • anchor

      public SpriteDraw anchor(double x, double y)
      Changes the anchor point, using fractions of the sprite's dimensions. Values outside 0 to 1 are permitted.
      Parameters:
      x - horizontal anchor fraction
      y - vertical anchor fraction
      Returns:
      drawing instructions with the new anchor
    • centered

      public SpriteDraw centered()
      Sets the anchor to the sprite's center.
      Returns:
      center-anchored drawing instructions
    • bottomCenter

      public SpriteDraw bottomCenter()
      Sets the anchor to the center of the sprite's bottom edge. Useful when positioning a character by its feet.
      Returns:
      bottom-center-anchored drawing instructions
    • at

      public SpriteDraw at(double x, double y)
      Returns drawing instructions at the given position.
      Parameters:
      x - horizontal position
      y - vertical position
      Returns:
      repositioned drawing instructions
    • at

      public SpriteDraw at(Vec2 position)
      Returns drawing instructions at the given position.
      Parameters:
      position - new position
      Returns:
      repositioned drawing instructions
    • translate

      public SpriteDraw translate(double dx, double dy)
      Moves the anchor by a displacement in screen coordinates, not along the sprite's rotated local axes.
      Parameters:
      dx - horizontal displacement in pixels
      dy - vertical displacement in pixels
      Returns:
      translated drawing instructions
    • translate

      public SpriteDraw translate(Vec2 offset)
      Moves the anchor by a displacement in screen coordinates.
      Parameters:
      offset - displacement vector
      Returns:
      translated drawing instructions
    • scale

      public SpriteDraw scale(double factor)
      Sets the uniform drawing scale.
      Parameters:
      factor - scale factor (nonnegative; 1 = original size)
      Returns:
      drawing instructions with the new scale
    • rotate

      public SpriteDraw rotate(double radians)
      Sets clockwise rotation about the anchor.
      Parameters:
      radians - angle in radians
      Returns:
      drawing instructions with the new rotation
    • flipX

      public SpriteDraw flipX(boolean enabled)
      Enables or disables horizontal mirroring.
      Parameters:
      enabled - whether to flip horizontally
      Returns:
      drawing instructions with the requested flip state
    • flipY

      public SpriteDraw flipY(boolean enabled)
      Enables or disables vertical mirroring.
      Parameters:
      enabled - whether to flip vertically
      Returns:
      drawing instructions with the requested flip state
    • flipX

      public SpriteDraw flipX()
      Enables horizontal mirroring.
      Returns:
      horizontally flipped drawing instructions
    • flipY

      public SpriteDraw flipY()
      Enables vertical mirroring.
      Returns:
      vertically flipped drawing instructions
    • tint

      public SpriteDraw tint(Color color)
      Sets a local image tint, including alpha. Tint multiplies sprite colors rather than replacing them. A null tint retains the current graphics tint.
      Parameters:
      color - tint, or null to inherit the current tint
      Returns:
      drawing instructions with the new tint
    • scaledBy

      public SpriteDraw scaledBy(double factor)
      Multiplies the current scale by a factor.

      Unlike scale(double), which sets the absolute scale, this method scales relative to the current value.

      Parameters:
      factor - multiplier (nonnegative)
      Returns:
      drawing instructions with the adjusted scale
    • 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.
    • sprite

      public Sprite sprite()
      Returns the value of the sprite record component.
      Returns:
      the value of the sprite record component
    • x

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

      public double y()
      Returns the value of the y record component.
      Returns:
      the value of the y record component
    • anchorX

      public double anchorX()
      Returns the value of the anchorX record component.
      Returns:
      the value of the anchorX record component
    • anchorY

      public double anchorY()
      Returns the value of the anchorY record component.
      Returns:
      the value of the anchorY record component
    • scale

      public double scale()
      Returns the value of the scale record component.
      Returns:
      the value of the scale record component
    • rotation

      public double rotation()
      Returns the value of the rotation record component.
      Returns:
      the value of the rotation record component
    • flippedX

      public boolean flippedX()
      Returns the value of the flippedX record component.
      Returns:
      the value of the flippedX record component
    • flippedY

      public boolean flippedY()
      Returns the value of the flippedY record component.
      Returns:
      the value of the flippedY record component
    • tint

      public Color tint()
      Returns the value of the tint record component.
      Returns:
      the value of the tint record component