Now it is fun. I did not realize that my handset has the accelerometer sensor until I saw the video. I didn’t even know that AIR for Android supports the thing. So I tried, and it worked! I modified the code from previous posts, removing multitouch events and adding simple AccelerometerEvent. This seems quite straightforward, and the only thing I still do not get is why it is called accelerometer while it aparently measures axis tilt, not acceleration.
Runtime check if the hardware supports us:
if(Accelerometer.isSupported){
accl = new Accelerometer();
accl.setRequestedUpdateInterval(200);
accl.addEventListener(AccelerometerEvent.UPDATE, handleAccelerometer);
}else{
tf.appendText('\naccelerometer NOT supported');
}
And the actual handler:
privatefunction handleAccelerometer(e:AccelerometerEvent):void{var n:int = sprites.length;
var s:Handle;
// loop through all alive sprites to update their speedfor(var i:int = 0; i < n ; i++){
s = sprites[i];
s.speedX -= e.accelerationX*10;
s.speedY += e.accelerationY*10;
}}// this exits the app on any key (event volume up/down!)privatefunction handleKey(e:KeyboardEvent):void{
NativeApplication.nativeApplication.exit();
}
Quick and dirty test, which surprisingly says my Wacom/Win7 do not support multitouch, but the HTC Desire does. And that is where I meant it.
This app shows red circles, each under its finger. In my case, maximum two at the same time.