cacheAsBitmap & cacheAsBitmapMatrix in Layman's Terms
DamonDeMers123 Nov 29, 2010 7:59 PMSorry... this is a bit of a long post with some code... I'm hoping some of the more experienced flash/iphone developers can help clarify a few things for me...
I'm a beginner AS3 developer; I've combed over the Adobe literature and the various threads in this forum and I'm still having trouble understanding when best to use cacheAsBitmap and cacheAsBitmapMatrix.
In simple terms, it appears that:
1.
mySprite.cacheAsbitmap = true;
Use for vectors graphics in order to cache them. This is easier on the device because the GPU can animate the bitmap much faster than the CPU can redraw the vector. Works for simple X and Y transitions (move an object across the screen).
(From Packager for iPhone Dev Guide: Setting cacheAsBitmap to true alone causes a display object (and any children) to be cached. The display object is not redrawn when new regions are exposed, or the whole combined graphic is translated.)
2.
matrix:Matrix = new Matrix();
mySprite.cacheAsBitmapMatrix = matrix;
mySprite.cacheAsBitmap = true;
Use the cacheAsBitmapMatrix property when you plan to scale or rotate the vector graphic.
(From Packager for iPhone Dev Guide: For display objects that have cacheAsBitmap set to true, setting cacheAsBitmapMatrix causes the GPU to use the bitmap that results from the matrix transformation. The GPU uses the bitmap representation even if the object is rotated or scaled. The GPU can composite and animate this bitmap much more quickly than the CPU can redraw a vector-rendered object.)
3.
Existing bitmap images used in the project are pre-cached.
(From JMP808 on this thread: http://forums.adobe.com/message/3244008#3244008:
CacheAsBitmap puts a bitmap version of display objects onto the GPU. Bitmaps are already pre-cached, so you only need to call cacheAsBitmap on items with vector components (eg if you do a graphics.drawCircle for instance, or you've drawn your character with the shape tools, as opposed to importing a JPG/PNG)
once the item is on the GPU (as a texture basically) the hardware can move the item around the screen quickly without reverting to the software renderer (which is slower). If you make any modifications to this cached item then it will need to go back to the software renderer. (Note however if you use cacheAsBitmapMatrix you can also use the hardware to scale, rotate and alpha the cached bitmap)
So in very simple terms it would seem that you could want to use the cacheAsBitmap property to vectors you planned to move around the screen but maintain proportions, cacheAsBitmap + cacheAsBitmapMatrix to vectors you wanted to scale, rotate, alpha and then, finally, completely avoid the process for png/jpg or other bitmap images because they are pre-cached.
Am I totally missing something? Oversimplifying? (most likely).




