In my previous entry I showed a simple function that allows you to take a snapshot of a movie clip. You can take that snapshot and then display it elsewhere. Since it is already cached, then forcing it to display is high speed.
You can take this one step further and cache animations. What you do is this:
1) Create an empty array
2) Take a snapshot of the current state of the movie clip (using the function in my previous post). Push this BitmapData object into the array.
3) Force the movie clip to the next frame and go back to step 2 until there are no frames left.
You can then play the animation back with excellent performance by using MovieClip.attachBitmap() and passing an element from the array in. Do this every frame walking through the array (one element per frame).
This example shows how you can cache a particle effect and then play it back. As a vector animation I think I could get 3 or 4 playing before the frame rate dropped. As a cached animation I can get more than 300 without the frame rate dropping.
Just click to add an effect. Click 'create lots' to add a buch to the floor.
Monday, May 7, 2007
Subscribe to:
Post Comments (Atom)
4 comments:
Nice work, Jobe. We're using this technique extensively now. We actually have some new "Kung-fu" we are perfecting that will render the entire screen as a bitmap on each iteration. We basically have ONE clip in the whole game, and it is just a holder for a bitmap made up of all the other bitmaps in the game. It is slick and fast.
Chris Cutler has a working demo at his desk right now.
-Jeff Fulton
Mattel
Awesome! I can't wait to see it!
Yup, I built a system to do this some time back and the performance change is amazing.
Somebody knows how to do this with as3?
Post a Comment