Record Class SpriteDraw
java.lang.Object
java.lang.Record
cit244.api.image.SpriteDraw
- Record Components:
sprite- the source spritex- horizontal position of the anchor, in pixelsy- vertical position of the anchor, in pixelsanchorX- 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 coordinatesflippedX- whether the sprite is mirrored horizontallyflippedY- whether the sprite is mirrored verticallytint- 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
ConstructorsConstructorDescriptionSpriteDraw(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 TypeMethodDescriptionanchor(double x, double y) Changes the anchor point, using fractions of the sprite's dimensions.doubleanchorX()Returns the value of theanchorXrecord component.doubleanchorY()Returns the value of theanchorYrecord component.at(double x, double y) Returns drawing instructions at the given position.Returns drawing instructions at the given position.Sets the anchor to the center of the sprite's bottom edge.centered()Sets the anchor to the sprite's center.final booleanIndicates whether some other object is "equal to" this one.booleanflippedX()Returns the value of theflippedXrecord component.booleanflippedY()Returns the value of theflippedYrecord component.flipX()Enables horizontal mirroring.flipX(boolean enabled) Enables or disables horizontal mirroring.flipY()Enables vertical mirroring.flipY(boolean enabled) Enables or disables vertical mirroring.final inthashCode()Returns a hash code value for this object.static SpriteDrawCreates 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.doublerotation()Returns the value of therotationrecord component.doublescale()Returns the value of thescalerecord component.scale(double factor) Sets the uniform drawing scale.scaledBy(double factor) Multiplies the current scale by a factor.sprite()Returns the value of thespriterecord component.tint()Returns the value of thetintrecord component.Sets a local image tint, including alpha.final StringtoString()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.Moves the anchor by a displacement in screen coordinates.doublex()Returns the value of thexrecord component.doubley()Returns the value of theyrecord component.
-
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 nullIllegalArgumentException- if any numeric value is non-finite or scale is negative
-
-
Method Details
-
of
Creates drawing instructions at native scale with a top-left anchor, no rotation, no flipping, and no local tint.- Parameters:
sprite- sprite to drawx- horizontal screen positiony- vertical screen position- Returns:
- default drawing instructions
-
anchor
Changes the anchor point, using fractions of the sprite's dimensions. Values outside 0 to 1 are permitted.- Parameters:
x- horizontal anchor fractiony- vertical anchor fraction- Returns:
- drawing instructions with the new anchor
-
centered
Sets the anchor to the sprite's center.- Returns:
- center-anchored drawing instructions
-
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
Returns drawing instructions at the given position.- Parameters:
x- horizontal positiony- vertical position- Returns:
- repositioned drawing instructions
-
at
Returns drawing instructions at the given position.- Parameters:
position- new position- Returns:
- repositioned drawing instructions
-
translate
Moves the anchor by a displacement in screen coordinates, not along the sprite's rotated local axes.- Parameters:
dx- horizontal displacement in pixelsdy- vertical displacement in pixels- Returns:
- translated drawing instructions
-
translate
Moves the anchor by a displacement in screen coordinates.- Parameters:
offset- displacement vector- Returns:
- translated drawing instructions
-
scale
Sets the uniform drawing scale.- Parameters:
factor- scale factor (nonnegative; 1 = original size)- Returns:
- drawing instructions with the new scale
-
rotate
Sets clockwise rotation about the anchor.- Parameters:
radians- angle in radians- Returns:
- drawing instructions with the new rotation
-
flipX
Enables or disables horizontal mirroring.- Parameters:
enabled- whether to flip horizontally- Returns:
- drawing instructions with the requested flip state
-
flipY
Enables or disables vertical mirroring.- Parameters:
enabled- whether to flip vertically- Returns:
- drawing instructions with the requested flip state
-
flipX
Enables horizontal mirroring.- Returns:
- horizontally flipped drawing instructions
-
flipY
Enables vertical mirroring.- Returns:
- vertically flipped drawing instructions
-
tint
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
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
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
sprite
-
x
-
y
-
anchorX
-
anchorY
-
scale
-
rotation
-
flippedX
-
flippedY
-
tint
-