Created
September 2, 2014 15:04
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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