First step : build your MovieClip with this frame order
Then Build and link a class for your MovieClip
package { import flash.display.MovieClip; public class Tank extends MovieClip { private const SLICE:Number = 4 / Math.PI; public function Tank() { this.stop(); } public function set angle(value:Number):void { this.gotoAndStop( Math.round(value * SLICE) + 5 ); // calc the frame } } }
Finally when you need to calculate the frame to render ; call your public method that convert an angle to a frame index.
_tank.angle = Math.atan2( mouseY - _tank.y, mouseX - _tank.x );
Demo
[swfobj src=”https://www.yopsolo.fr/wp/wp-content/uploads/2013/07/Dir8Animation.swf” width=”640″ height=”480″]
This nice tank is an Harkonen heavy tank from the game Dune 2