A Few Things You May Not Know About CacheAsBitmap
cacheAsBitmap is a feature in Flash (since Flash
that tells the Flash Player to store a movieclip of vectors into one static instance in memory. It’s a great way to boost the performance of your Flash.
But I’m writing about how to use cacheAsBitmap (you can just google that).
Some things you may never knew about cacheAsBitmap.
- With the exception of changing position, if a movieclip animates with cacheAsBitmap set to true, performance will slow down. This is because the Flash Player must recalculate the vectors and reload the Bitmap instance into memory. Moving x or y doesn’t change the vectors of the movieclip and thus will not affect performance.
- cacheAsBitmap is automatically set to true whenever a filter is set on a movieclip.
- A movieclip moving with cacheAsBitmap set to true, the movieclip will probably not animate smoothly. Unless the displacement values are round numbers, the movieclip will seem to move in a zig zag.
Example:
clip.cacheAsBitmap = true;
clip.onEnterFrame = function() {
this._x += 1;
this._y += 1;
};
Will look fine…
clip.cacheAsBitmap = true;
clip.onEnterFrame = function() {
this._x += 1.5; // Decimal displacement makes things shaky
this._y += 1.5;
};
Won’t.
Just take a look at the following example… Is the red dot shaking or is it just me? Maybe it’s scared of the blue dot.
2 comments to “A Few Things You May Not Know About CacheAsBitmap”
June 11th, 2008 at 4:15 am
It’s because the bitmap data has to snap to pixels. You can’t render a bitmap on half a pixel – it has to be whole values (otherwise your talking about sub pixel rendering!), but you can calculate a vector on decimal values, therefor using antialiasing it render smoother.
February 6th, 2011 at 10:59 pm
This frustrates me. Basically cacheAsBitmap defaults to no smoothing and there’s no control over it. After all these years it’s still better for animation to pre-render your effects as bitmaps in some other program and import them, just so you can turn smoothing on when you move them so it doesn’t look terrible.