Thursday 14 July 2011

Broke it to fix it

CodingImage by ronny-andre via Flickr
Warning : Spoilers

On Livestock Vs The Undead Lite v1.1b (the 'b' was due to a couple of quick releases to eradicate some memory issues) I was at a stage to really start ploughing in some new functionality. (I apologise at this point if you've been waiting for the new release - below explains why there has been a delay.) This was going well at first. The persistent levels code was working well. I had added another creep along with extra chomping animations and sounds. A dozen or so tweaks around the system were holding their own.

That's when my old enemy, the Out-Of-Memory monster reared its ugly head. I was stuck, nowhere to turn, banging my head on my keyboard (getting dfghjk in reverse on my forehead). Then it dawned on me.

The code I was using loaded all of the game's 100+ sprites individually, resizing them on the fly. It was this that was chomping through the memory at a rate of knots. Even though the combined size of all the sprites was less than 1.6Mb - the processing just overwhelmed the device and all came crashing down. So the bright idea I had was that of consolidating all of the sprites into one .png file.

I started adjusting the code to handle the process. Unfortunately I realised quite quickly that this wasn't going to work either. The memory error had disappeared, but the Out-Of-Memory monster's poor second cousin, the Logistical-Nightmare monster, popped up.

You see, my sprites are all different shapes and sizes. This meant that the consolidated spritemap was all over the place. And given that you are always working with relative positions due the device rescaling, mapping where everything was, it turned out to be like playing darts in a tornado.

Not one to give up without a fight I decided to find the middle ground. This ended up being several sprite sheets with like-sized sprites. This meant that simple division worked effectively to work out sprite positions and that fewer picture files kept OOM away. Yay, success!

So, I currently am basically back to square one in terms of how the game plays, but now I can make some quick progress getting the more interesting stuff in for v1.2 (which I am hoping to have out of the door in a couple of weeks time).

I'm currently working on the menus at the moment - trying to give them a slicker feel.


Paul
Enhanced by Zemanta

No comments:

Post a Comment

Your message will appear once it has been approved. Thanks for your interest.