Posted November 30, 2023 by KanedaFr
#lynx
Today I finally took the time to optimize the way to define sprites.
Actually, you have to write, for EACH sprite, this kind of line of the main makefile
src/gfx/hero1_01.spr:src/gfx/game_assets.bmp $(SPRPCK) -s4 -p2 -t6 -o128010 -S016022 -a010000 -r001001 $< $(basename $@)
If your sprites are loaded from standalone bitmap, the process is easier but if you're using a tileset, it takes hours to get sprite position, size and anchor using any image editor.
And if you ever update the source tileset, you have to restart !
For this game, the required tileset is made of 200+ sprites so I had to find another way.
I don't remember how and where, but I recently learnt about the "slice" feature of Aseprite, mainly used to support patch9 on Unity.
I was reading the doc about it and it explains how you can export the data on a json file.
I'm not a python fan but it supports json natively so I gave it a go.
At first, I was only planning to parse the file and extract some values...but it ran so smoothly that some hours later, I was able to convert the JSON to a makefile!
It allowed me to clean the main makefile which was a mess full of sprites definition.
So, if you're interested :
Edit your tileset under Aseprite
Export the json on Export spritesheet
Add it with the tileset in BMP format (required by sprpck) on your source folder
Add the python script on makefile path
Edit the 2 vars on top of the script (segment and sprpck)
Update your makefile
assets_makefiles=src/game_assets.mk all: $(assets_makefiles) %.mk:%.json python3 convert.py -a $(basename $@).bmp include src/game_assets.mk
This will convert the JSON to a makefile
Of course, sprite will only be generated if requested to be linked to the rom.