当前位置: 代码迷 >> Web前端 >> AS3基础:圆周运动(二)
  详细解决方案

AS3基础:圆周运动(二)

热度:386   发布时间:2012-06-27 14:20:08.0
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;
			}
		}
		
	}

}

?

?

?

?



?