`
ycy303
  • 浏览: 194436 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

as3写的自由落体

阅读更多

Ball类

package {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    /**
    * ...
    * @author ycy 2008.3.18
    */
    public class Ball extends MovieClip {
        private var t:Timer;
        private const G:Number = 0.1;
        private var vy:Number = 0;
        public function Ball() {
        t = new Timer(10);
        t.addEventListener(TimerEvent.TIMER, move);
        t.start();
    }
    public function move(e:Event):void {
        vy += G;
        this.y += vy;
        if (y > 370) {
            this.y = 370;
            vy *= -0.9;
            trace(vy);
            if (Math.abs(vy) < 0.8) {
                this.y = 370;
                 t.removeEventListener(TimerEvent.TIMER,move);
             }
         }
      }
   }
}

 Main文档类

 

package {
    import flash.display.MovieClip;
    import flash.events.Event;
     import flash.events.MouseEvent;
    /**
    * ...
    * @author ycy 2008.3.18
    */
    public class Main extends MovieClip
    { 
        public function Main() {
            stage.addEventListener(MouseEvent.CLICK,clickHandle);
        }
        private function clickHandle(e:Event):void {
            var ball:Ball = new Ball();
            ball.x = mouseX;
             ball.y = mouseY;
             addChild(ball);
         }
      }
}

 

2008.3.18

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics