Graphics Programs Reference
In-Depth Information
r
(xc, yc)
Ball
r = (Mask width) / 2 - (Ball width) / 2
Mask
Figure 5.19 Calculating the radius of the ball path
This gives us what we are after and only needs to be converted to ActionScript as shown
below. We'll also set the starting angle of the object to 0 degrees.
1
2
3
4
5
6
7
8
// define the circular path characteristics
xc = Stage.width/2; // horizontal center of circle
yc = Stage.height/2; // vertical center of circle
r = mask_mc._width/2-object_mc._width/2; // radius
// set the object starting angle in degrees
angle = 0;
Step 3: Position the object on the circle
Since we want the object to follow the circular orbit, we need to place it on the curve.
Rather than physically placing the object, we will do it with scripting and a little trig.
Let's define a function setObject that will place the ball on the circle for any angle
using similar expressions to that of Figure 5.17.
9
10
11
12
13
14
15
16
// set the object on the circle
function setObject()
{
a = angle*Math.PI/180;
object_mc._x = xc + r * Math.cos(a);
object_mc._y = yc + r * Math.sin(a);
}
 
Search WWH ::




Custom Search