topical media & game development

talk show tell print

animation-ch18-MatrixRotate.ax

animation-ch18-MatrixRotate.ax [swf] [flash] flex


  package
  {
   import flash.display.Sprite;
   import flash.events.Event;
   import flash.geom.Matrix;
   import flash.display.StageAlign;
   import flash.display.StageScaleMode;
  
   public class @ax-animation-ch18-MatrixRotate extends Sprite
   {
    private var angle:Number = 0;
    private var box:Sprite;
    
    public function @ax-animation-ch18-MatrixRotate()
    {
     init();
    }
  

init(s)


    private function init():void
    {
     stage.align = StageAlign.TOP_LEFT;
     stage.scaleMode = StageScaleMode.NO_SCALE;
     box = new Sprite();
     box.graphics.beginFill(0xff0000);
     box.graphics.drawRect(-50, -50, 100, 100);
     box.graphics.endFill();
     addChild(box);
     addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
    
  

frame(s)


    private function onEnterFrame(event:Event):void
    {
     angle += .05;
     var cos:Number = Math.cos(angle);
     var sin:Number = Math.sin(angle);
     box.transform.matrix = new Matrix(cos, sin,
              -sin, cos,
               stage.stageWidth / 2,
               stage.stageHeight / 2);
    }
   }
  }
  


(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.