public class SpriteSheet
- Object
- 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.
Constructors
public SpriteSheet(Image sheet, int frameWidth, int frameHeight) | Creates a sprite sheet over the given image. |
Methods
public int getColumns() | The number of frame columns in the sheet. |
public int getRows() | The number of frame rows in the sheet. |
public int getFrameCount() | The total number of frames (columns times rows). |
public int getFrameWidth() | |
public int getFrameHeight() | |
public Image getFrame(int index) | Returns the frame at the given linear index, cutting and caching it on first access. |
public Image getFrame(int col, int row) | Returns the frame at the given column and row. |
Inherited methods
Constructor details
SpriteSheet
public SpriteSheet(Image sheet, int frameWidth, int frameHeight)Creates a sprite sheet over the given image.
Parameters
sheetImage- the atlas image
frameWidthint- width of a single frame in pixels
frameHeightint- 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
public Image getFrame(int index)Returns the frame at the given linear index, cutting and caching it on first
access.
getFrame
public Image getFrame(int col, int row)Returns the frame at the given column and row.