Flex脚本代码 学习加速力与方向的用法

发布时间:2020-12-04编辑:脚本学堂
本文分享一例Flex代码,学习加速效果时有关力与方向的用法,有需要的朋友参考下吧。

Flex脚本,加速力与方向的用法。
代码:

复制代码 代码示例:
package {
    import flash.display.Sprite;
    import flash.events.Event;
   
    public class Main extends Sprite {
        private var _sprite:Sprite = new Sprite(  );
        private var _ax:Number = .2;
        private var _ay:Number = .1;
        private var _vx:Number = 0;
        private var _vy:Number = 0;
        var angle:Number = 45;
        var accel:Number = .5;
        public function Main(  ) {
            _sprite.graphics.beginFill(0x0000ff, 100);
            _sprite.graphics.drawCircle(0, 0, 25);
            _sprite.x = 5;
            _sprite.y = 10;
            addChild(_sprite);
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
       
        public function onEnterFrame(event:Event):void {
          var radians:Number = angle * Math.PI / 180;
      _ax = Math.cos(radians) * accel;
      _ay = Math.sin(radians) * accel;
            _vx += _ax;
            _vy += _ay;
            _sprite.x += _vx;
            _sprite.y += _vy;
        }
    }   
}