Mobile app version of vmapp.org
Login or Join
LarsenBagley460

: Automated way to extract irregularly sized sprites from a sprite sheet 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

@LarsenBagley460

Posted in: #AdobePhotoshop #Automation #BatchProcessing #Sprite

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?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @LarsenBagley460

2 Comments

Sorted by latest first Latest Oldest Best

 

@Vandalay110

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:

./divide_vert -i spritesheet.png line-%02d.png
montage line-*.png -rotate 90 -geometry '1x1<' -tile 1x -background none joined.png
./divide_vert -i joined.png sprite-%03d.png
mogrify -rotate 270 sprite-*.png


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.



Ps. ImageMagick's montage command is also handy for creating sprite sheets, as in this answer on the Game Development Stack Exchange.

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.

10% popularity Vote Up Vote Down


 

@Shelton719

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).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme