Game Development Reference
one-point projection . Figure 11.13 illustrates how four dif-
ferent objects look when using the same vanishing point.
all DisplayObjects would be rather limiting, so Flash
allows us to assign each DisplayObject its own vanish-
ing point. By default, every new object uses the center
of the Stage as its vanishing point. Unfortunately, mul-
tiple vanishing points cannot be assigned within the
Flash authoring environment. This must be done
through ActionScript using the transform property of
DisplayObjects. Starting in CS4, Transform objects now
have a new property called perspectiveProjection. This
object allows us to set the vanishing point for any
given DisplayObject. Let
Figure 11.13 Four DisplayObjects rotating
toward a single vanishing point.
s look at a few lines of script,
applied to the same clips shown in Fig. 11.13 .
clip1.transform.perspectiveProjection = new
clip2.transform.perspectiveProjection = new
clip1.transform.perspectiveProjection.projectionCenter = new
clip2.transform.perspectiveProjection.projectionCenter = new
clip3.transform.perspectiveProjection = clip1.transform.
clip4.transform.perspectiveProjection = clip2.transform.
In this example, we create two new PerspectiveProjection objects,
one positioned at the left-hand side of the screen and the other at the
right. Figure 11.14 shows the result of this script; the two clips on the
left skew to the left, while those on the right skew to the right.
With that basic overview of the 3D abilities of Flash, let
s look at
a practical example using the math covered earlier in this chapter.
It is similar to the premise behind Atari
s classic arcade game
Tempest . The player controls a character at the mouth of a long
tunnel that appears to start at the screen in first-person view and
diminishes into the distance. We
ll use the trig functions and some
Vanishing point 1
Vanishing point 2
Figure 11.14 Two pairs of
DisplayObjects, each with its
own vanishing point.