topical media & game development

talk show tell print

animation-ch13-Walking4.ax

animation-ch13-Walking4.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-Walking4 extends Sprite
   {
    private var segment0:animation_ch13_Segment;
    private var segment1:animation_ch13_Segment;
    private var segment2:animation_ch13_Segment;
    private var segment3:animation_ch13_Segment;
    private var cycle:Number = 0;
    private var offset:Number = -Math.PI / 2;
    
    public function @ax-animation-ch13-Walking4()
    {
     init();
    }
  

init(s)


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

frame(s)


    private function onEnterFrame(event:Event):void
    {
     walk(segment0, segment1, cycle);
     walk(segment2, segment3, cycle + Math.PI);
     cycle += .05;
    }
    
    private function walk(segA:animation_ch13_Segment, segB:animation_ch13_Segment, cyc:Number):void
    {
     var angleA:Number = Math.sin(cyc) * 45 + 90;
     var angleB:Number = Math.sin(cyc + offset) * 45 + 45;
     segA.rotation = angleA;
     segB.rotation = segA.rotation + angleB;
     segB.x = segA.getPin().x;
     segB.y = segA.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.