AS3运动学基础-抛物线

package  
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.utils.getTimer;
	/**
	 * ...
	 * @author hacker47
	 */
	public class Main2  extends MovieClip
	{
		// set gravity amount
		var gravity:Number = .00098;
		// set starting velcity
		var dx:Number = .2;
		var dy:Number = -.8;
		// mark start time and add listener
		var lastTime:int = getTimer();
			
		public function Main2() 
		{
			addEventListener(Event.ENTER_FRAME, animateBall);
		}
		
			
			
			// step animation
			function animateBall(event:Event)
			{
				// get time difference
				var timeDiff:int = getTimer()-lastTime;
				lastTime += timeDiff;

				// adjust vertical speed for gravity
				dy += gravity*timeDiff;

				// move ball
				ball.x += timeDiff*dx;
				ball.y += timeDiff*dy;
			}
			/*
			y轴速度随时间的推移受重力的影响。
			这就是一个简单的模拟现实世界
			*/
		
	}

}

 

 

 

这里有个同学解释得挺清楚的:http://www.samhy.com/article/57.htm

你可能感兴趣的:(as3)