Bash scripts to split & merge animated sprite sets

Avatar

By MirceaKitsune 1 Feb 2020 14:57

Member · 45 comments

I'm in the process of creating my own game / mod for Tuxemon, which obviously involves editing lots of graphics. The biggest issue are overland sprites: The engine doesn't keep them in a single file containing all frames, but expects each frame to be stored as its own file under the format:

bob_back.png
bob_back_walk.000.png
bob_back_walk.001.png
bob_back_walk.002.png
bob_back_walk.003.png
bob_front.png
bob_front_walk.000.png
bob_front_walk.001.png
bob_front_walk.002.png
bob_front_walk.003.png
bob_left.png
bob_left_walk.000.png
bob_left_walk.001.png
bob_left_walk.002.png
bob_left_walk.003.png
bob_right.png
bob_right_walk.000.png
bob_right_walk.001.png
bob_right_walk.002.png
bob_right_walk.003.png

Opening and editing 20 sprites in Gimp individually is a huge pain: It's much easier to edit everything as one image!

To make this possible and my work a lot easier, I put together two simple bash scripts to convert back and forth between a single sprite sheet and individual files with the expected names. Running it only requires having ImageMagick installed, as well as either running Linux or a bash interpreter for Windows. I'm sharing my scripts here as well in case it helps other artists who need them to edit such sprites: Feel free to do anything you'd like with them!

Usage: Create two empty files called merge.sh and split.sh, don't forget to set them as executable. Add the following content blocks to each one in the order mentioned. Drop your sprite set in the same directory, then call the script with its name as a parameter, such as "merge.sh bob".

#!/bin/bash 

montage ${1}_*.png -tile x1 -geometry 16x32 -background "#ffffff00" ${1}.png
#!/bin/bash 

convert -crop 16x32 ${1}.png -background "#ffffff00" ${1}_%02d.png

mv ${1}_00.png ${1}_back.png
mv ${1}_01.png ${1}_back_walk.000.png
mv ${1}_02.png ${1}_back_walk.001.png
mv ${1}_03.png ${1}_back_walk.002.png
mv ${1}_04.png ${1}_back_walk.003.png
mv ${1}_05.png ${1}_front.png
mv ${1}_06.png ${1}_front_walk.000.png
mv ${1}_07.png ${1}_front_walk.001.png
mv ${1}_08.png ${1}_front_walk.002.png
mv ${1}_09.png ${1}_front_walk.003.png
mv ${1}_10.png ${1}_left.png
mv ${1}_11.png ${1}_left_walk.000.png
mv ${1}_12.png ${1}_left_walk.001.png
mv ${1}_13.png ${1}_left_walk.002.png
mv ${1}_14.png ${1}_left_walk.003.png
mv ${1}_15.png ${1}_right.png
mv ${1}_16.png ${1}_right_walk.000.png
mv ${1}_17.png ${1}_right_walk.001.png
mv ${1}_18.png ${1}_right_walk.002.png
mv ${1}_19.png ${1}_right_walk.003.png

Last edited by MirceaKitsune (1 Feb 2020 14:59)

Avatar

By MirceaKitsune 1 Feb 2020 16:45

Member · 45 comments

As an added bonus: This tool should be able to immediately decompile sets generated by Sanglorian's "Build Your Own Protagonist" tool. The frames seem to be in the same alphabetical order so it likely works identically.

https://forum.tuxemon.org/thread.php?id=195