3

Okay, so I am working on a mobile app in OpenFL and Haxe. I would like to gather input from the gyroscope, or more specifically about the orientation of the phone. I have searched the openfl docs, and google for some kind of documentation or examples on this sort of thing. I had no luck there and would like to know if anyone could point me toward some.

1 Answers1

6
  1. Make a new Accelerometer:

    private var _acc:Accelerometer = new Accelerometer();
    
  2. Add an event listener to it:

    _acc.addEventListener(AccelerometerEvent.UPDATE, updateAcc);
    
  3. Listen to results:

    private function updateAcc(Event:AccelerometerEvent):Void 
    {
        trace("x:" + Event.accelerationX);
        trace("y:" + Event.accelerationY);
        trace("z:" + Event.accelerationZ);
    }
    

Note than iOS accelerometer values are inverted.

Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97