RSS

Acceleration Animation with Actionscript 3

03 Jul

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;
        
        public function Main(  ) {
            _sprite.graphics.beginFill(0x0000ff100);
            _sprite.graphics.drawCircle(0025);
            _sprite.x = 5;
            _sprite.y = 10;
            addChild(_sprite);
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        public function onEnterFrame(event:Event):void {
            _vx += _ax;
            _vy += _ay;
            _sprite.x += _vx;
            _sprite.y += _vy;
        }
    }    
}  

———————OR Try with this  ————————–
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(0x0000ff100);
            _sprite.graphics.drawCircle(0025);
            _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;
        }
    }    
}

Click here for More detail

 

Advertisements
 
Leave a comment

Posted by on July 3, 2011 in Action Script3

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: