Graphics Programs Reference
In-Depth Information
The displayObj() function is where we need to apply aerial perspective. We'll define a
color value variable colval that represents the tint that we want to apply to an object.
In most cases, this value will be related to the z-coordinate of the object or its distance
ratio. In this particular example, we are taking the larger of either -125 or the negative
z-coordinate of the object. Once the value has been determined, the color setTransform
method is called to modify the color of the object as shown below. The range of values
can be from -255 (black) to +255 (white).
74
75
76
77
// set the tint based on the z-location of the shape
// to provide aerial perspective ( -255 to +255 )
colval = Math.max(-125, -thisObj.z);
thisObj.myColor.setTransform({rb:colval, gb:colval,
bb:colval})
78
We are using only three of eight properties available, rb , gb , and bb , which are offset
values for the red, green, and blue components of a Color object. It is also possible to
specify percentages of the components as well as alpha values. Note that in our exam-
ple, we are applying equal values to the offsets, which uniformly affects the color. By
increasing one while decreasing the others, we could make an object look as if it were
under a red light, a blue light, and so forth. There is no one formula that works for all
occasions, and some experimenting is usually required to get the effect you are after.
The movement of the objects on their circular path is carried out as usual with an
onEnterFrame handler. There are several types of movement available. The user can
press on the arrow buttons to rotate the objects clockwise or counterclockwise. This
movement is continuous for as long as the user presses down on a button and will stop
when the button is released. The button variables, next and back , control the motion.
The user can also click on an object to bring it to the foreground. When an object is
selected, it becomes the target for movement (lines 100-105), and all objects will
rotate either clockwise or counterclockwise until the selected object is under the spot-
light. If the clicked object is to the right of center, the objects will rotate in a clockwise
direction (line 111). If the clicked object is to the left of center, the objects will rotate
in a counterclockwise direction (line 112).
In order to ensure that the buttons, title, and spotlight are never covered up, they
are placed on top using swapDepths() , similar to what we have done in the games.
Initially, the arrow buttons were defined as actual buttons, but swapDepths() cannot
Search WWH ::




Custom Search