Lu Aye's
Blog, images and projects: Feed
LuAye.com
RSS Feed 
| All | Life | Ideas and thoughts | Reviews | Shout out | News | Coding |
<Previous Post Next Post>
BitmapMovieClip - Flash ActionScript 3
  Coding
Just want to share a code lib that is saving my current physics based flash game's performance by 10 fold.
Tags: Bitmap MovieClip, Animated Bitmap, Sequenced Bitmap, for flash AS3

What is it?
This class is essencially a Bitmap class that can hold sequence of BitmapData.

Imagine you have a lot (say 100s) of non-interactive movieclip that have the same animation (but not necerrially all show the same frame at the same time).
If you make new movieClips to accompany all clips it will be very slow to render the vectors every frame...
with BitmapMovieClip, it caches all the frames of the movieclip in an array of BitmapData and use the same bitmapData across all instances. Therefore it only need to store a single sequence of BitmapData and can be reused.


Advantages:
- Doesnt have to duplicate bitmaps for the number of movieclips you need.
- Very fast as it doesn't need to render vectors.
- It got most functionality (and more) of MovieClip, such as play()/stop()/gotoAndPlay()
- support labels

When you shouldn't use:
- If your movieclip have simple vectors. There is no point to turn them into bitmapsData.
- If there is only 1 frame in movieclip, just use Bitmap class.
- Highly nested movieClips may not work as intended.
- Scaling will pixelate, you can pre scale before generating the clip tho.
- HitTests will return the rectangle area of the clip, rather than the vector's shape.

To be careful:
If you make changes to the bitmapData of a frame in the sequence, it will update in all clips unless you set 'useClone' to true.

Example: Click here
Example demonistrates by generating lots of clips to be played on screen at once. There you can see which runs faster clearly. - you might need to play with clip count to see the difference depending on your machine.

Source: Click here


Why are you giving this?
Bored I guess :P

  Post a Comment
Name :
Email :
Comment :