Record Class SpriteSheet
java.lang.Object
java.lang.Record
cit244.api.image.SpriteSheet
- Record Components:
image- source imagetileW- width of each cell in pixelstileH- height of each cell in pixelsmargin- pixels before the first row and columnspacing- pixels between adjacent cells
public record SpriteSheet(Image image, int tileW, int tileH, int margin, int spacing)
extends Record
A regular grid of sprite regions within an image.
Columns and rows are zero-based, starting at the top-left cell. Margins are measured from the image edges, and spacing is the number of pixels between adjacent cells. For example:
SpriteSheet sheet = image.grid(16, 16).margin(1).spacing(1);
Sprite pose = sheet.at(2, 0); // third cell in the first row
-
Constructor Summary
ConstructorsConstructorDescriptionSpriteSheet(Image image, int tileSize) Creates a grid of square cells without margins or spacing.SpriteSheet(Image image, int tileW, int tileH) Creates a grid without margins or spacing.SpriteSheet(Image image, int tileW, int tileH, int margin, int spacing) Checks the dimensions, margin, and spacing. -
Method Summary
Modifier and TypeMethodDescriptionat(int col, int row) Selects a cell by column and row, starting from (0, 0).final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.image()Returns the value of theimagerecord component.intmargin()Returns the value of themarginrecord component.margin(int pixels) Returns a sheet with a different margin.intspacing()Returns the value of thespacingrecord component.spacing(int pixels) Returns a sheet with different spacing between cells.inttileH()Returns the value of thetileHrecord component.inttileW()Returns the value of thetileWrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SpriteSheet
Creates a grid without margins or spacing.- Parameters:
image- source imagetileW- cell width in pixelstileH- cell height in pixels
-
SpriteSheet
Creates a grid of square cells without margins or spacing.- Parameters:
image- source imagetileSize- cell side length in pixels
-
SpriteSheet
Checks the dimensions, margin, and spacing.- Throws:
NullPointerException- if image is nullIllegalArgumentException- if cell dimensions are not positive, or margin or spacing is negative
-
-
Method Details
-
margin
Returns a sheet with a different margin.- Parameters:
pixels- margin before the first row and column (nonnegative)- Returns:
- the updated sheet
-
spacing
Returns a sheet with different spacing between cells.- Parameters:
pixels- space between adjacent cells (nonnegative)- Returns:
- the updated sheet
-
at
Selects a cell by column and row, starting from (0, 0).- Parameters:
col- zero-based columnrow- zero-based row- Returns:
- sprite for the selected cell
- Throws:
IllegalArgumentException- if the cell is outside the image
-
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. -
image
-
tileW
-
tileH
-
margin
-
spacing
-