Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

When to Use Bitmap Caching

When to Use Bitmap Caching

If used correctly, bitmap caching can dramatically reduce the amount of updating instructions that the renderer has to process in every frame, and your applications should, in practice, run a lot quicker and smoother. However, in certain circumstances bitmap caching could have a detrimental effect on the performance of your Flash application, therefore you should choose the movie clips you cache wisely.

Bitmap caching works best for movie clips whose visual appearance doesn’t change often or not at all. This is because when a cached movie clip or its contents change, Flash regenerates the bitmap with new data for the area or region of vector data that changed and updates the bitmap held in memory. The renderer then displays the new bitmap.

Bitmap caching also works well for movie clips that contain complex vector data (for example, shapes with lots of curves or gradient fills), as it is quicker for the renderer to copy a bitmap from memory onto the Stage than to draw all those vectors to the Stage.

Every time you rotate, scale, or change the alpha of a cached movie clip, the whole bitmap has to be regenerated. So, turning on bitmap caching for a movie clip that is constantly rotating, changing in size, or contains an animation doesn’t make much sense because in every frame the renderer has to update the bitmap to reflect the new appearance of the movie clip as well as redraw it to the Stage, which adds overhead.

On the other hand, bitmap caching works well for both static movie clips and movie clips that move, as long as they don’t change visually. It is perfectly fine to move a cached movie clip around the Stage, either with ActionScript or with Timeline animation, because moving it around won’t change its visual appearance. The cached bitmap doesn’t have to be updated, and the renderer will merely draw the bitmap at its new position.

Valid Use-Case Scenario

Consider the following use-case scenario:

You have a large application that contains multiple Window components; each Window component contains numerous other components. Each Window component is draggable. When the user drags one of the Window components around the application, he notices a slowdown—the Window component has to catch up to the mouse position, which causes jerky movement. To fix this problem, the developer turns on bitmap caching for each Window component instance. Now the player only has to update the internal bitmap representation of each Window component when the visual appearance of one of the UI components inside it changes. The rest of the time—even when the Window component is being dragged around—the player simply needs to move the bitmaps around the Stage, as opposed to constantly updating the Stage from the vector data in each movie clip. The result is a much smoother dragging experience for the user.

When Are Surfaces Regenerated?

As stated previously, changes to a movie clip that make the player regenerate the internal bitmap representation should be used sparingly; otherwise you defeat the purpose of the feature. With bitmap caching on for a movie clip, Flash Player will regenerate the bitmap every time you change any of the following MovieClip ActionScript properties:

  • _xscale
  • _yscale
  • _rotation
  • _alpha
  • _width
  • _height
  • filters
  • blendMode
  • opaqueBackground
  • transform

So, when using bitmap caching, try to avoid changing any of these ActionScript properties on a regular basis.

The bitmap will also be regenerated when:

  • The Timeline playhead changes inside the movie clip
  • When the outer boundaries of the movie clip change
  • When you draw something inside the movie clip with the Drawing API
  • When you attach an image or symbol from the Library into the movie clip
  • Any of the above occur within a nested movie clip (child movie clip)
  • The movie’s viewing window changes (for example, the viewer zooms in on the movie by right-clicking and choosing Zoom)