Caching Animation Frames VS Spritesheets
Apparantly drawing each frame of an animation to a single bitmap and then selecting a region to display is better for memory and speed than keeping each frame in its own bitmapData object.
The issue i’ve had is that for larger animations a sprite sheet of 2880×2880 is a little restrictive. To counter this ive modified bit101′s BigAssCanvas to allow a copyPixels of a rect, in order to get our frame data from a BIG Sprite sheet. This makes the test a little unfair, but small spritesheets are not an option for us.
The results are as follows:
cached as frames: ~120fps
cached on spritesheet: ~70fps
frames: 249 856
spritesheet: 270 336
so caching each frame seems the way to go for us. There doesnt seem to be any advantage in the spritesheet. It might run faster if it was a single bitmapData object and direct coptyPixels – but who’s to say
This entry was posted on Friday, November 28th, 2008 at 4:08 pm and is filed under Flash. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
March 18th, 2009 at 12:35 pm
this is awesome! Where did you get the idea to do this? I’m working on a pretty big platformer project right now and might have draw my sprites like this eventualy aswell. Where did you get the idea to try and render it this way?
March 18th, 2009 at 12:47 pm
I think it was actually a pretty original idea. We just needed a way of getting non-stupidly-simple animations to play quickly in Flash and we asked ourselves why they didn’t, why our old SNES could do it, but our 12Ghz machine slowed to a crawl.
We were already caching our backgrounds like this (to make things faster, it’s even faster than just setting cacheAsBitmap=true) so it was just the next logical step I guess.
Warning, it does take a lot of memory, though we were surprised at how fast Flash is at doing the caching at all.
March 18th, 2009 at 1:19 pm
Thanks for sharing!
http://lts3.algonquincollege.com/matthias/platformer/ heres a link to the project I’ve been working on (this is not quite the latest build). Make sure you select a level before going “play now” or it will load nothing. Also press M to go back to the menu and then options to adjust some of the settings if it goes too slow.
I’ve build the engine from the ground up but have been very frustrated with performance issues. I will definitly have to look into the way your caching stuff works.
I have also seen that scary girl project you are working on. Great stuff man cant wait to see it once its complete!
March 18th, 2009 at 2:11 pm
heh thanks, I work for a college and in my department we make educational flash games for the mistry of education that get disributed to kindergardens, grade schools, and high schools. Most of them are very simple but we are in the process of making some more interesting ones.
That one there will eventualy platformer game with tones of different themed levels with educational material that the players are forced to learn as they progress. Its a cool consept but right now I’m the only developer working on it and it keeps getting put aside to work on other projects.
I’m also in the process of working on another platformer using box2dflash.
I’ll post some links to everything once I get my website and blog back up and running haha
June 6th, 2009 at 2:21 pm
Great work here guys. I was perusing through the code and notice a reference to the following:
I searched for info regarding “e_bound”s but could find nothing, would you elaborate on what exactly this “e_bounds” is.
June 16th, 2009 at 12:54 pm
e_bounds is a movieclip which is used to define the ‘bounds’ of the aimation. Say the first frame is empty, but obviously there is stuff on the following frames. Without defining the bounds of the whole animation the code would not know the region to cache as bitmapData. We found it easy to put a clip in there, so you can resize and arrange it visually, as you want. Hope that helps.
March 17th, 2010 at 7:52 pm
i have 105 fps on first run. But when i resize flash window my fps go ~35 and don’t go up(((