Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Two of the more important members of the math class are the sine and cosine functions. Go ahead and open up from the Work Files folder the Draw underscore Math underscore Class.fla file. Open up the Actions Panel. Click on the first frame of the Actions Layer and you'll see this script here. Go ahead and experiment with the original sine wave position for both cosine and the sine. I'm going to go ahead and start off with 100 here and 200 for the cosine. Choose a sine wave color and a cosine wave color by changing the hexadecimal value and then the multiplier for the wave that will be created and then the wave stretcher variable. I'm setting mine initially to 15 but you can experiment with those values. Notice here I'm setting up a variable that runs on a for loop for I equals one less than the stage width so that way the waves that I'm going to be drawing stay on stage. Here I'm setting up variables for the sine position using the math class here, the function math sine cosine. Then I'm drawing the shapes down here using the graphics.draw rectangle method. There are my parameters for the shapes that I'm drawing. Go ahead and do a Control Test Movie and there are my two wave forms that I'm drawing out and two different colors. Let's go ahead and change the multiplier value and the stretch value from 15 to 25. Again, kind of experiment with the settings here. Draw larger sine and cosine waves. If you open up the Draw underscore COS underscore Sine.fla file, you'll see this script that utilizes the cosine and sine functions to draw out a circle. First up here we declare the speed, how fast the angle is increasing decreasing. Then we assign a radius for the circle right here. Again, I recommend that you experiment with these numbers to really understand how they're affecting the graphics that will be created by this script. In this case we want the circle to be at the center of the stage so center X and center Y are the variables. And I do that with this construct: number equals stage.stagewidth divided by two. Take the whole stage width, divide it by two, make that center X. Take the stage height, divide that by two, make that center Y. Then we're setting the line style right here of the graphics that I'm creating so if you go ahead and change the number here and then retest the movie, you can see the differences that the values make. The next line then sets the starting point to be the circle's right side. The enter frame functions calculates the new X and Y positions using cosine and sine. We increase the angle in each frame and draw a line to the new coordinate with this function right there. Let's go ahead and do a Control Test Movie to see the results. And there is the line that I'm drawing; kind of a nice little function that draws that in real time. Let's go ahead and change the radius from 150 to 100 and the speed number from .5 to .2, Control Test Movie. It's going to draw a smaller circle more slowly. Let's now make some further modifications to the script: change my radius back to 150 to draw a nice, big circle. Let's change the speed, make this faster. Go to .09. Let's change the line style here from 2 to 5. This'll make a thicker line. Control Test Movie; so a larger circle drawn faster and it's thicker. And lastly, if we change the center point by adjusting that script from 2 to 3, notice it's going to be off centered in the horizontal direction over there to the left. So there you have a nice script for drawing out arcs and circles as well as the script previously for drawing out sine waves and cosine waves. Now, another math class that you'll probably need in your game is one for calculating distances. So let me now move on to the next movie and review scripts for calculating the distances between two objects, between an object and the user's mouse pointer or even between two moving objects on the stage.
| Course: | Adobe Flash ActionScript 3.0 for Designers |
| Author: | James Gonzalez |
| SKU: | 34060 |
| ISBN: | 1-935320-82-3 |
| Release Date: | 2009-11-09 |
| Duration: | 9.5 hrs / 101 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |