Monday, October 6, 2014

Start Animations and Memory Management in Construct 2


Things are slowing down and I've been able to add some more animation to my Superhero Game.  Namely, the the top half of the "start" animations in flight.  Granted, I was really just using the full "start" animation from flying to the right or left.  The cape fully extends so I can just pull out a few frames and it works pretty good.  The animations for flying down will be trickier because I'll actually have to hand draw the cape flapping upwards and over the head.  I ran into a little trouble with overlapping animations stuttering, but got that ironed out quick.

My newest consideration is the memory management in the game.  I've noticed that the download size (only 4 megs) is a far stretch from the memory used (118 megs).  I couldn't figure it out until today when Scirra posted about memory management.  Turns out, it doesn't matter how much memory your image file uses, the file gets converted to a 32 bit format that needs 4kb for every pixel when the game is started.  So even though a single frame of my animation is only about 3.7kb as a PNG file, it doesn't matter because the file is converted.  My player animation has at least 200 frames already.  The images are cropped, but start at 160 x 160px.  So that's a lot.

We'll see how drastically this affects me the in the future.  I might need to get smarter about my memory use.

-Ben  

4 comments:

  1. Nice! I have the same jack-of-all-trades um...problem? Problem is Im not super good at any of it but Im pretty good at a lot.
    Also CaptainZero has gigantic animations. Some are like 13mb worth of pngs for 1 thing so its good to know how that affects performance.

    ReplyDelete
    Replies
    1. Glad to know I'm not the only one. I was pretty shocked by the way that Construct 2 converts image files. I was priding myself on how small my file sized were, and it actually didn't help me at all. I still plan on having a lot of animation in the game though. I might have to smarten up and get better at tile art and look seriously at Spriter for enemies. Might use Spriter for NPC's too, but I'd rather not.

      Delete
  2. 160x160 x 200 frames is only around 100kb.

    Most memory that overhead is from the browser, not your game or images.You are preoptimizing and not really understanding the technical aspect. The best way to move forward is to keep working on your game and only optimize when it's actually a problem.

    ReplyDelete
    Replies
    1. Really? I hope you're right, but Scirra put on the blog post (link below, look in Calculating Image Memory Use) that images are converted to 32 bit and each pixel is 4 kb. I think that's why my memory use is so far above my download size. https://www.scirra.com/manual/183/memory-usage

      Delete