I have a sprite sheet from a classic video game (if you're curious, Final Fight) that I'd like to be broken up into indivual images to be used in GameSalad. However, the images aren't on an even grid, and all have a different amount of space between them.

Is there an automated way to export images based on contiguous pixels or something like that?

2 Answers
2

You can do this with ImageMagick and this helper script. The script only splits the image vertically, but that's fine — we can rotate the resulting strips by 90 degrees and try again.

(This is all assuming that you're working on Linux, Mac OS X or some other Unix-line OS, since the script is a Unix bash shell script. If you're on Windows, I suppose you could try running it under Cygwin. And, of course, you obviously need to have ImageMagick installed, although if you're using Linux there's a good chance that you already do.)

Specifically, if you've saved the image in your question as spritesheet.png and the script as divide_vert in the current directory, and made the script executable with chmod 755 divide_vert, the following shell commands ought to do the job:

The montage command is a bit tricky, since it does two things at the same time: rotating the lines by 90 degrees clockwise and joining them into a single tall strip so that we can split them all with just one more call to the script. The funny-looking -geometry and -tile options tell montage not to resize the source images, as it would normally do, and to arrange them in a single vertical column. For more information about how they work, see this page.

The second divide_vert pass will probably take a bit more time than the first. Just give it half a minute or so and it should be done. All the other steps should be pretty quick.

Pps. I'm sure there are other ImageMagick scripts out there that can do the job, this was just the first one I found. Another one, which has more features and can do the entire job in one pass, is this one called "multicrop". Unfortunately, for this task, the multicrop script is perhaps a bit too advanced: you need to disable the unrotation feature and reduce the grid spacing down to 1 to get the expected results, and even then it's a bit too zealous in splitting up the sprites, such that e.g. the few disconnected pixels below the jumping sprite get split into a separate image. It's also rather slow if you have a lot of sprites on the sheet.

Sprite sheets should have the same size for each frame so that you don't get this problem. Thats what a sprite atlas is for, when you create a sprite atlas with images like these the program you use will create offsets for each frame so its easy to use in other programs like game salad and they take up less space.

The problem here is that you are using a sprite atlas allready made and you havent got the offset information. The best way I can think of is to use Photoshop or similar and sperate each frame with the desired size and then use an atlas generator to make the atlas for you (http://www.codeandweb.com/texturepacker I like this one, can also be done manually just more work).