topical media & game development

talk show tell print

animation-ch13-Walking1.ax

animation-ch13-Walking1.ax [swf] [flash] flex


  package {
   import flash.display.Sprite;
   import flash.display.StageScaleMode;
   import flash.display.StageAlign;
   import flash.events.Event;
  
   public class @ax-animation-ch13-Walking1 extends Sprite
   {
    private var segment0:animation_ch13_Segment;
    private var segment1:animation_ch13_Segment;
    private var cycle:Number = 0;
    
    public function @ax-animation-ch13-Walking1()
    {
     init();
    }
  

init(s)


    private function init():void
    {
     stage.scaleMode = StageScaleMode.NO_SCALE;
     stage.align = StageAlign.TOP_LEFT;
     
     segment0 = new animation_ch13_Segment(100, 20);
     addChild(segment0);
     segment0.x = 200;
     segment0.y = 200;
     
     segment1 = new animation_ch13_Segment(100, 20);
     addChild(segment1);
     segment1.x = segment0.getPin().x;
     segment1.y = segment0.getPin().y;
     
     addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
   

frame(s)


    private function onEnterFrame(event:Event):void
    {
     cycle += .05;
     var angle:Number = Math.sin(cycle) * 90;
     segment0.rotation = angle;
     segment1.rotation = segment0.rotation + angle;
     segment1.x = segment0.getPin().x;
     segment1.y = segment0.getPin().y;
    }
   }
  }
  


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