Moving an Object in a Specific Direction : Direction : Animation Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Animation » Direction »

 

Moving an Object in a Specific Direction


 
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    
    public class Main extends Sprite {
        private var _sprite:Sprite = new Sprite(  );
        private var _angle:Number = 135;
        private var _speed:Number = 4;
        private var _timer:Timer;
        
        public function Main (  ) {
            _sprite.graphics.beginFill(0x0000ff100);
            _sprite.graphics.drawCircle(005);
            _sprite.graphics.endFill(  );
            _sprite.x = 300;
            _sprite.y = 100;
            addChild(_sprite);
            _timer = new Timer(3);
            _timer.addEventListener("timer", onTimer);
            _timer.start(  );
        }
        
        public function onTimer(event:TimerEvent):void {
            var radians:Number = _angle * Math.PI / 180;
            var vx:Number = Math.cos(radians* _speed;
            var vy:Number = Math.sin(radians* _speed;
            _sprite.x += vx;
            _sprite.y += vy;
        }
    }    
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Animation
» Direction