Skip to content

Instantly share code, notes, and snippets.

@stewsters
Created September 2, 2014 15:04
Show Gist options
  • Save stewsters/de011d60181cee980e05 to your computer and use it in GitHub Desktop.
Save stewsters/de011d60181cee980e05 to your computer and use it in GitHub Desktop.
This code splits a tileset into individual tiles. I use it for naming files and selecting specific tiles before TexturePacking them in LibGDX
import javax.imageio.ImageIO
import java.awt.image.BufferedImage
int tileSize = 32
BufferedImage source = ImageIO.read(new File("fantasy-tileset.png"))
assert source
for (int x = 0; x < source.width / tileSize; x++) {
for (int y = 0; y < source.height / tileSize; y++) {
BufferedImage output = source.getSubimage(tileSize * x, tileSize * y, tileSize, tileSize)
ImageIO.write(output, 'png', new File("output/${y}x${x}.png"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment