AS3基础:圆周运动(2)

 package  
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author hacker47
	 */
	public class Main2 extends Sprite 
	{
		private var radius:Number = 200;
		private var angle:Number = 0;
		private var xPos:Number;
		private var yPos:Number;
		private var speed:Number = .1;
		private var startPoint:Point = new Point(300, 300);
		
		public function Main2() 
		{
			if (stage) init();
			else
				addEventListener(Event.ADDED_TO_STAGE, init);
				
		}
		
		private function init(e:Event = null):void {
			graphics.lineStyle(1, 0, 1);
			graphics.moveTo(startPoint.x+radius, startPoint.y);
			addEventListener(Event.ENTER_FRAME, running);
		}
		
		private function running(e:Event):void {
			xPos =startPoint.x+ Math.cos(angle) * radius;
			yPos =startPoint.y+ Math.sin(angle) * radius;
			graphics.lineTo(xPos, yPos);
			angle += speed;
			trace(angle*180/Math.PI);
			if (angle*180/Math.PI > 360) {
				angle = 0;
			}
		}
		
	}

}

 

 

 

 


AS3基础:圆周运动(2)
 

你可能感兴趣的:(as3)