topical media & game development

talk show tell print

animation-ch10-Rotate2.ax

animation-ch10-Rotate2.ax [swf] [flash] flex


  package
  {
   import flash.display.Sprite;
   import flash.events.Event;
   import flash.display.StageScaleMode;
   import flash.display.StageAlign;
  
   public class @ax-animation-ch10-Rotate2 extends Sprite
   {
    private var ball:animation_ch10_Ball;
    private var vr:Number = .05;
    private var cos:Number = Math.cos(vr);
    private var sin:Number = Math.sin(vr);
    
    public function @ax-animation-ch10-Rotate2()
    {
     init();
    }
  

init(s)


    private function init():void
    {
     stage.scaleMode = StageScaleMode.NO_SCALE;
     stage.align = StageAlign.TOP_LEFT;
     ball = new animation_ch10_Ball();
     addChild(ball);
     ball.x = Math.random() * stage.stageWidth;
     ball.y = Math.random() * stage.stageHeight;
     addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
   

frame(s)


    private function onEnterFrame(event:Event):void
    {
     var x1:Number = ball.x - stage.stageWidth / 2;
     var y1:Number = ball.y - stage.stageHeight / 2;
     var x2:Number = cos * x1 - sin * y1;
     var y2:Number = cos * y1 + sin * x1;
     ball.x = stage.stageWidth / 2 + x2;
     ball.y = stage.stageHeight / 2 + y2;
    }
   }
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.