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);  } 

Tip

Don't place code on frames in multiple layers . Create a layer specifically for frame actions to make it easy to find them during the development process. Labels can be especially difficult to find if they are followed closely by other keyframes, unless they are on a designated layer.




Inside Flash
Inside Flash MX (2nd Edition) (Inside (New Riders))
ISBN: 0735712549
EAN: 2147483647
Year: 2005
Pages: 257
Authors: Jody Keating

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net