PDA

View Full Version : Flash and double-buffering


Jesse Aldridge
11-13-2006, 11:26 AM
What's the deal with double buffering in Flash? Is it handled automatically? Do you have to implement it yourself? Does Flash have some other method of preventing tearing?

iopred
11-13-2006, 02:13 PM
Flash does not have a buffer, because of the nature of it's display model, (where code is executed, then the display is drawn from a tree of objects) you will never have tearing. The drawback, is that code execution is dependent on rendering speed and visa-versa.

You can Double Buffer if you choose, by using BitmapData and drawing everything to that, however you will see no speed increase, and in some cases, a decline in speed. (Though to be fair, there are some cases where this could be useful).

Indiepath
11-13-2006, 03:02 PM
Flash also uses the DirtyRect method and only draws to the region of the buffer that requires updating. Hence a compiled .exe version works faster than a web-embedded version.

DGuy
11-13-2006, 05:24 PM
... because of the nature of it's display model, (where code is executed, then the display is drawn from a tree of objects) you will never have tearing.
If by the above it is meant that the Vertical Retrace Interval (VRI) will some how be accounted for, then the comment is incorrect. The Flash Player does not wait for the VRI thus there can/will be tearing.

I happen to have the Flex2 help window open so here is the basic help info about display list:

Understanding the display architecture
Each application built with ActionScript 3.0 has a hierarchy of displayed objects known as the display list. The display list contains all the visible elements in the application. Display elements fall into one or more of the following groups:


The Stage

The Stage is the base container of display objects. Each application has one Stage object, which contains all onscreen display objects. The Stage is the top-level container and is at the top of the display list hierarchy:

Each SWF file has an associated ActionScript class, known as the main class of the SWF file. When you embed a SWF file in an HTML page, Flash Player calls the constructor function for that class and the instance that is created (which is always a type of display object) is added as a child of the Stage object. The main class of a SWF file always extends the Sprite class (for more information, see Core display classes).

You can access the Stage through the stage property of any DisplayObject instance. For more information, see Setting Stage properties.


Display objects

In ActionScript 3.0, all elements that appear on screen in an application are types of display objects. The flash.display package includes a DisplayObject class, which is a base class extended by a number of other classes. These different classes represent different types of display objects, such as vector shapes, movie clips, and text fields, to name a few. For an overview of these classes, see Core display classes.


Display object containers

Display object containers are special types of display objects that can contain child objects that are also display objects.

The DisplayObjectContainer class is a subclass of the DisplayObject class. A DisplayObjectContainer object can contain multiple display objects in its child list. For example, the following illustration shows a type of DisplayObjectContainer object known as a Sprite that contains various display objects:

In the context of discussing display objects, DisplayObjectContainer objects are also known as display object containers or simply containers.

Although all visible display objects inherit from the DisplayObject class, the type of each is of a specific subclass of DisplayObject class. For example, there is a constructor function for the Shape class or the Video class, but there is no constructor function for the DisplayObject class.

As noted earlier, the Stage is a display object container.

HTH

LilGames
11-14-2006, 01:38 PM
You can simulate your own double-buffer via bitmapData and copyPixel, but as mentioned already, there is NO v-sync, so you just can't avoid tearing. It's one of the big complaints from Flash game devs. (I wonder though if wrapping it with Directory would help)