Class SpriteSheet

java.lang.Object
com.codename1.gaming.SpriteSheet

public class SpriteSheet extends Object

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 Details

    • SpriteSheet

      public SpriteSheet(Image sheet, int frameWidth, int frameHeight)

      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

      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.