• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 25. Storyboarding to Finished Project > Tank Movement: Comparing Angles

Tank Movement: Comparing Angles

To rotate the tanks, I needed to be able to compare two angles. Whenever you want to compare two angles in Flash, you need to the shift the difference into the range of 0–360. This ensures that you’re not measuring more than once around or that the difference is negative. Because the values for Flash 5’s _rotation property range from –180 to 180, comparing two angles sometimes results in a value that is below 0 or above 360. If the result is not shifted into the range of 0–360, the tank will still end up in the right place, but it will rotate around several times before getting there. I created a new fixAngle() function in frame 1 on the main timeline to do this:

// Once two angles have been compared, they must be converted 
// to a floating scale (0-360 range) 
function fixAngle (angle) {
    while (angle<0) {
        angle += 360; 
    } 
    while (angle>360) {
        angle -= 360; 
    } 
    return (angle); 
} 


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint