topical media & game development

talk show tell print

lib-flex-animation-code-06-VerletStickTest.ax

lib-flex-animation-code-06-VerletStickTest.ax (swf ) [ flash ] flex


  package {
          import flash.display.Sprite;
          import flash.display.StageAlign;
          import flash.display.StageScaleMode;
          import flash.events.Event;
          import flash.geom.Rectangle;
  
          public class @ax-lib-flex-animation-code-06-VerletStickTest extends Sprite
          {
                  private var _pointA:VerletPoint;
                  private var _pointB:VerletPoint;
                  private var _stick:VerletStick;
                  private var _stageRect:Rectangle;
                  
                  public function @ax-lib-flex-animation-code-06-VerletStickTest()
                  {
                          stage.align = StageAlign.TOP_LEFT;
                          stage.scaleMode = StageScaleMode.NO_SCALE;
                          _stageRect = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
                          
                          _pointA = new VerletPoint(100, 100);
                          _pointB = new VerletPoint(105, 200);
                          
                          _stick = new VerletStick(_pointA, _pointB);
                          
                          addEventListener(Event.ENTER_FRAME, onEnterFrame);
                  }
                  
                  private function onEnterFrame(event:Event):void
                  {
                          _pointA.y += .5;
                          _pointA.update();
                          
                          _pointB.y += .5;
                          _pointB.update();
                          
                          for(var i:int = 0; i < 5; i++)
                          {
                                  _pointA.constrain(_stageRect);
                                  _pointB.constrain(_stageRect);
                                  _stick.update();
                          }
                          
                          graphics.clear();
                          _pointA.render(graphics);
                          _pointB.render(graphics);
                          _stick.render(graphics);
                  }
          }
  }
  


(C) Æliens 18/6/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.