Graphics Programs Reference
In-Depth Information
The test says that if the object is less than or equal to 40 pixels from the camera, then
turn the visibility of the object off, otherwise turn the visibility on. If you're wondering
where the 40 pixels comes from, it was obtained by a quick trial and error of different
values.
Step 5: Add a final refinement
As our final step, let's add a little aerial perspective. In some of the previous examples
and exercises we've done that by varying the alpha of the objects. This works in certain
situations such as when there is a fairly uniform light or dark background or when you
have objects that have some transparency to begin with. Recall that when we discussed
aerial perspective in Chapter 2, we mentioned blurring and an overall color blending
into the background as characteristics of aerial perspective. Let's look at how we can
control the amount of blurring based on an object's depth. We'll save the color blending
for a later discussion.
Here's what we want to do. When the puppies are close to us, we want them to be
in sharp focus. As they move farther back in space, we want them to become more
blurred. Fortunately, Flash 8 with ActionScript 2 makes this an easy job. Filters such as
a Blur filter, a Drop Shadow filter, and others are available in their own package called
flash.filters . Movie clips now have a property called filters , which is an array
containing the filters that have been applied to it. Although we will be applying only a
Blur filter, it is possible to have multiple filters assigned to an object.
The parameters that need to be defined for a Blur filter are blurX, blurY , and quality .
The first two represent the amount of horizontal and vertical blur respectively. Separate
blur factors in the x- and y-directions enable motion blur effects. In our case we will want
the blur to be uniform, so we will use the same value for each. The quality is the num-
ber of times to perform the blur. We will use a medium value of 3, which approximates a
Gaussian Blur filter.
To apply the blur filter in our case involves only a few lines of code as shown below. We
first define the variable blur , which takes an object's z-coordinate, divides by 100, and
38
39
40
41
42
43
thisObj.z += camdz;
// apply a blur filter based on depth value
var blur:Number = Math.round(thisObj.z/100);
thisObj.filters = [new flash.filters.BlurFilter(blur,blur,3)];
 
Search WWH ::




Custom Search