自己独立完成的第一个动画-平抛曲线的生成
学了一周多点的时间自己试着编了一个平抛曲线的动画,但是心里并没有像当年第一次写出自己的VBA程序那样兴奋了。不知啥原因。
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class Ex026 extends Sprite
{
private var vx:Number=12;
private var vy:Number=0;
private var ay:Number=0.5;
private var arrow:Arrow;
public function Ex026()
{
init();
}
private function init():void
{
arrow=new Arrow(Math.random()*0xff0000);
arrow.scaleX=0.5;
arrow.scaleY=0.5;
addChild(arrow);
arrow.x=0;
arrow.y=0;
stage.addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
graphics.moveTo(arrow.x,arrow.y);
vy+=ay;
arrow.y+=vy;
arrow.x+=vx;
graphics.lineTo(arrow.x,arrow.y);
graphics.lineStyle(1,0.1);
graphics.endFill();
if(arrow.x+arrow.width/2>stage.stageWidth||arrow.y+arrow.height/2>stage.stageHeight)
{
stage.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
}
}
}
}