Tested And Working - Detect if Device has been Shaken
by Andrea Farid Marsili · in iTorque 2D · 05/08/2011 (2:32 am) · 0 replies
Here a simple way to detect if the device has been shaken.
In "projectFiles/game/scripts/game.cs" uncomment the following line:
Then modify accelerometerY:
And here the resetShake() function:
In "projectFiles/game/scripts/game.cs" uncomment the following line:
new ActionMap(moveMap); moveMap.bind(joystick0, xaxis, "accelerometerX"); moveMap.bind(joystick0, yaxis, "accelerometerY"); moveMap.push();
Then modify accelerometerY:
function accelerometerY(%val){
if(%val > 0.5){
$shakeLeft = true;
echo("Shake Left: " @ $shakeLeft);
schedule(1000, 0, "resetShake");
}
if(%val < -0.5){
$shakeRight = true;
echo("Shake Right: " @ $shakeRight);
schedule(1000, 0, "resetShake");
}
if($shakeRight == true && $shakeLeft == true){
$shakingDevice = true;
echo("Shaking Device: " @ $shakingDevice);
schedule(1000, 0, "resetShake");
}
}And here the resetShake() function:
function resetShake(){
if($shakeLeft){
$shakeLeft = false;
echo("Shake Left: " @ $shakeLeft);
}
if($shakeRight){
$shakeRight = false;
echo("Shake Right: " @ $shakeRight);
}
if($shakingDevice){
$shakingDevice = false;
echo("Shaking Device: " @ $shakingDevice);
}
echo("resetShake() called");
}