Class SpriteSheet
java.lang.Object
com.codename1.gaming.SpriteSheet
Slices a single texture atlas image into a grid of equally sized frames.
Frames are addressed either by linear index (row major, starting at 0) or by
column/row. Each frame is cut once with
com.codename1.ui.Image#subImage(int, int, int, int, boolean) and then cached,
because cutting a sub image copies pixel data and is far too expensive to repeat
every animation frame.
-
Constructor Summary
ConstructorsConstructorDescriptionSpriteSheet(Image sheet, int frameWidth, int frameHeight) Creates a sprite sheet over the given image. -
Method Summary
Modifier and TypeMethodDescriptionintThe number of frame columns in the sheet.getFrame(int index) Returns the frame at the given linear index, cutting and caching it on first access.getFrame(int col, int row) Returns the frame at the given column and row.intThe total number of frames (columns times rows).intintintgetRows()The number of frame rows in the sheet.
-
Constructor Details
-
SpriteSheet
Creates a sprite sheet over the given image.
Parameters
-
sheet: the atlas image -
frameWidth: width of a single frame in pixels -
frameHeight: height of a single frame in pixels
-
-
-
Method Details
-
getColumns
public int getColumns()The number of frame columns in the sheet. -
getRows
public int getRows()The number of frame rows in the sheet. -
getFrameCount
public int getFrameCount()The total number of frames (columns times rows). -
getFrameWidth
public int getFrameWidth() -
getFrameHeight
public int getFrameHeight() -
getFrame
Returns the frame at the given linear index, cutting and caching it on first access. -
getFrame
Returns the frame at the given column and row.
-