1 Reply Latest reply on Jul 21, 2011 6:14 PM by psisexpensive

    Accelerometer not smooth (ANDROID AIR)

    RobFacks

      Can I get some help on this.

       

      I did an as class to test the Accelerometer with a sprite and it is all choppy.

       

      here is the code...

      package
      {
          import flash.display.MovieClip;
          import flash.display.Sprite;
          import flash.events.AccelerometerEvent;
          import flash.events.Event;
          import flash.sensors.Accelerometer;
          import flash.display.StageAlign;
          import flash.display.StageScaleMode;

       

         
          public class AccelerometerBall extends Sprite
          {
              //public var _sphere:MovieClip = new test_mc() as MovieClip;
              public var textMC:MovieClip = new textField_mc() as MovieClip;
              public var _accelerometer:Accelerometer = new Accelerometer();
              public var _sphere:Sprite = new Sprite();
             
         
         
                 
              public function AccelerometerBall()
              {
                  stage.frameRate = 4;
                  stage.align = StageAlign.TOP_LEFT;
                  stage.scaleMode = StageScaleMode.NO_SCALE;
                 
                  _sphere = new Sprite();
                  _sphere.graphics.beginFill(0xFF000F);
                  _sphere.graphics.drawCircle(10, 10, 20);
                  _sphere.cacheAsBitmap = true;
                  _sphere.x = stage.stageWidth / 2;
                  _sphere.y = stage.stageHeight / 2;
                  addChild(_sphere);

       

                 
                 
                  addChild(textMC);
                  if (Accelerometer.isSupported)
                  {
                      _accelerometer.addEventListener(AccelerometerEvent.UPDATE,moveObject);
                  }
                  else
                  {
                      textMC.text_txt.width = 200;
                      textMC.text_txt.text = "Accelerometer not supported.";
                  }
         
              }
             
              public function moveObject (event:AccelerometerEvent):void
              {
                  stage.frameRate = 100;
                 
                 
                 
                  _sphere.x -= (event.accelerationX * 200);
                  _sphere.y += (event.accelerationY * 50);
                 
                  textMC.text_txt.width = 200;
                  textMC.text_txt.height = 200;
                  textMC.text_txt.text = "accelerationX = " + event.accelerationX +
                      "\naccelerationY = " + event.accelerationY +
                      "\naccelerationZ = " + event.accelerationZ +
                      "\ntimestamp = " + event.timestamp + "\nframeRate = " + stage.frameRate;
                 
                  if (_sphere.x < 0) {
                      _sphere.x = 0;
                  } else if (_sphere.x > stage.stageWidth) {
                      _sphere.x = stage.stageWidth;
                  }
                 
                  if (_sphere.y < 0) {
                      _sphere.y = 0;
                  } else if (_sphere.y > stage.stageHeight)
                  { _sphere.y = stage.stageHeight;
                  }

       

              }
             
          }
      }