Graphics Programs Reference
In-Depth Information
Step 7: Define the checkTheMouse function
There are three horizontal locations of the cursor that we need to address: the left
side of the Stage, the right side of the Stage, and the center of the Stage. The function
below deals with each of those cases. The function says that if the horizontal location
of the cursor ( _xmouse ) is less than 10 pixels from the center of the Stage, then
panLeft() . Otherwise, if the horizontal location of the cursor is greater than 10 pixels
from the center of the Stage, then panRight() . Otherwise, dontPan() the image at all.
13
14
15
16
17
18
19
checkTheMouse = function()
{
if (_xmouse < centerX - 10) { panLeft() }
else if (_xmouse > centerX + 10 ) { panRight() }
else dontPan();
}
Step 8: Define the panLeft() function
Add the lines below to your script. When the cursor is on the left side of the screen, we
want to simulate a viewer turning left. The visual equivalent of that panning motion is
to move the image to the right (line 22). If this were the only statement in the handler,
the image would move as desired, but ultimately, we would run out of image, and it
would proceed to keep on moving right off the Stage.
20
21
22
23
24
25
panLeft = function()
{
pano_mc._x += moveAmount;
if (pano_mc._x > xmax) { pano_mc._x -= pano_mc._width/2 }
}
We have to put some restrictions on the movement of the panorama to prevent this
from happening. At the same time, we need to remember our objective of having
continuous motion of the panorama for a full 360-degree rotation. Also, recall that
we made a duplicate of the image, so that we have two of them in our movie clip. It's
time to find out the reason for it and why line 23 has the necessary restrictions on the
movement of the panorama to the right. We'll discuss this in the next two steps.
Search WWH ::




Custom Search