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

Download Télécharger

This nice tank is an Harkonen heavy tank from the game Dune 2


Vote in HexoSearch