2 posts in a day - man, I’m on fire!
Before I get started on my next game project, I thought I should address my woeful lack of tool support, since it tends to lead to a certain amount of corner-cutting and inefficiency. First up, spritesheets!
Sheep Snaggers 2‘s engine code had pretty decent support for rendering from single texture spritesheets, but since packing all my sprites together and working out the co-ordinates by hand was frankly a massive pain in the arse it only really got used for a couple of animations. I ended up actively resisting the idea of adding new animations because I couldn’t be bothered with the donkey-work.
Since automating the donkey-work is pretty much what computers are for I thought I should address that by writing something to build the spritesheets for me - so this afternoon I finally pulled my finger out and the result was Spritepacker.py
A brief google suggested that if I wanted it to be really efficient I’d be dealing with a variation on a classic NP Hard problem, which is a bit more than I want to tackle on a lazy Sunday afternoon. A bit more googling found this example for packing lightmaps which looks like a nice simple interpretation of the First Fit Descending algorithm listed on Wikipedia. I tried it out with the Sheep Snaggers sprites and it seemed to do a pretty good job, anyway.