Posts Tagged ‘draw

05
Sep
08

Using Flash’s Drawing API and bitmap blitting.

This is a fairly simple, yet still compelling way of using some of Flash’s built in features to create some cool effects. Despite continual increases in processor speed and graphic card performance, there is still a need to optimize animations within your Flash files, particularly when creating animations programatically.

The following example utilizes the Drawing API to create short line segments. I’ve used Zeh Fernando’s group of Actionscript methods found in MC_Tween to handle the “pen” movement around the screen. Each segment is drawn into a hidden movieClip.

A Bit About “Blitting”

For those of you not familiar with the process of “blitting”, it is actually a programming approach that has been around for some time. Originally called a “BitBlit”, it was a series of routines used by early developers of computer graphics to control drawing operations. The primary function of BitBlit was to copy bitmap graphics from one location to another. These routines were later streamlined in modern languages, and evolved into a function simplified as blit().

At the time of this writing, Actionscript does not have a built-in function called “blit”, but the process can be simulated by utilizing Flash’s built in bitmapData methods. In Actionscript we use the method draw().

This approach is used to lessen the strain on the Flash Player. Normally the player would have to render multiple objects on a screen, sending them to Flash Player’s display processor, each time the Stage is updated. In a situation where you might have 1000 sprites moving around the screen, the end result would be a creeping movement that severely impacts the user experience, especially in game applications.

By “blitting” or drawing the sprites located in a hidden movieClip, into a single bitmap, the result is that Flash only has to render that single bitmapData object. There is no need to spend precious processing cycles on anti-aliasing of multiple vector objects. And the performance benefits are quite impressive.

See the demo here.
Get the source here.




April 2024
S M T W T F S
 123456
78910111213
14151617181920
21222324252627
282930