Class SpriteSheetSplitter

java.lang.Object
com.codingame.gameengine.module.entities.SpriteSheetSplitter

public class SpriteSheetSplitter extends Object
Utility to load an image containing several subimages displayed in sequential rectangles.

Will extract each separate image and return generated names that can be used to create a Sprite or SpriteAnimation

  • Constructor Details

    • SpriteSheetSplitter

      @Inject public SpriteSheetSplitter(GraphicEntityModule graphicEntityModule)
      The constructor expected to be called by Guice. Use GraphicEntityModule.createSpriteSheetSplitter() to instantiate
      Parameters:
      graphicEntityModule - the singleton to be injected
  • Method Details

    • getName

      public String getName()
      Returns the prefix of all subimage names
      Returns:
      the prefix of all subimage names
    • getSourceImage

      public String getSourceImage()
      Returns the image from which subimages will be extracted
      Returns:
      the image from which subimages will be extracted
    • getWidth

      public int getWidth()
      Returns the width of subimages
      Returns:
      the width of subimages
    • getHeight

      public int getHeight()
      Returns the height of subimages
      Returns:
      the height of subimages
    • getOrigRow

      public int getOrigRow()
      Returns from which row of subimages to start extracting subimages
      Returns:
      from which row of subimages to start extracting subimages
    • getOrigCol

      public int getOrigCol()
      Returns from which column of subimages to start extracting subimages
      Returns:
      from which column of subimages to start extracting subimages
    • getImageCount

      public int getImageCount()
      Returns number of subimages to extract
      Returns:
      number of subimages to extract
    • getImagesPerRow

      public int getImagesPerRow()
      Returns number of subimages to extract per row. Extraction will continue at origCol on the next row.
      Returns:
      number of subimages to extract per row. Extraction will continue at origCol on the next row.
    • setName

      public SpriteSheetSplitter setName(String name)
      Sets the prefix of all subimage names.
      Parameters:
      name - the prefix of all subimages
      Returns:
      this SpriteSheetSplitter
    • setSourceImage

      public SpriteSheetSplitter setSourceImage(String sourceImage)
      Sets the image from which to extract subimages
      Parameters:
      sourceImage - the image from which to extract subimages
      Returns:
      this SpriteSheetSplitter
    • setWidth

      public SpriteSheetSplitter setWidth(int width)
      Sets the width of the subimages to extract Defaults to full width of spritesheet if not set
      Parameters:
      width - the width of the subimages
      Returns:
      this SpriteSheetSplitter
    • setHeight

      public SpriteSheetSplitter setHeight(int height)
      Sets the height of the subimages to extract Defaults to full height of spritesheet if not set
      Parameters:
      height - the height of the subimages
      Returns:
      this SpriteSheetSplitter
    • setOrigRow

      public SpriteSheetSplitter setOrigRow(int origRow)
      Sets the row of subimages from which subimages start being extracting
      Parameters:
      origRow - the row of subimages from which subimages start being extracting
      Returns:
      this SpriteSheetSplitter
    • setOrigCol

      public SpriteSheetSplitter setOrigCol(int origCol)
      Sets the column of subimages from which subimages start being extracting
      Parameters:
      origCol - the column of subimages from which subimages start being extracting
      Returns:
      this SpriteSheetSplitter
    • setImageCount

      public SpriteSheetSplitter setImageCount(int imageCount)
      Sets the number of subimages to be extracted
      Parameters:
      imageCount - the number of subimages to be extracted
      Returns:
      this SpriteSheetSplitter
    • setImagesPerRow

      public SpriteSheetSplitter setImagesPerRow(int imagesPerRow)
      Sets the number of subimages to extract per row before advancing to the origColth column of the next row.
      Parameters:
      imagesPerRow - the number of subimages to extract per row before advancing to the origColth column of the next row.
      Returns:
      this SpriteSheetSplitter
    • split

      public String[] split()
      Splits up a spritesheet (all fields are required except imagesPerRow). Returns an array of image names that can be used in Sprite or SpriteAnimation.
      Returns:
      an array of image names.