HTML and CSS Reference
In-Depth Information
Example 10-2 shows the code necessary to do this. Notice we are placing it under the
current application start code (the new code is in bold).
Example 10-2. The gesture code added to BS Bingo
theCanvas.addEventListener("mousemove", onMouseMove, false);
theCanvas.addEventListener("click", onMouseClick, false);
initSounds();
initButtons();
initLists();
chooseButtonsForCard();
drawScreen();
var accelerationWatchId = null;
startAccelerationWatch();
function startAccelerationWatch() {
// Update acceleration every 3 seconds
var options = { frequency: 100 };
accelerationWatchId = navigator.accelerometer.watchAcceleration
(onSuccess, onError, options);
}
function stopAccelerationWatch() {
if (accelerationWatchId) {
navigator.accelerometer.clearWatch(accelerationWatchId);
accelerationWatchIdD = null;
}
}
function onSuccess(acceleration) {
if (Math.abs(acceleration.x) > 2 || Math.abs(acceleration.y)>2
|| Math.abs(acceleration.z)>2) {
alert('Acceleration X: ' + acceleration.x + '\n' +
'Acceleration Y: ' + acceleration.y + '\n' +
'Acceleration Z: ' + acceleration.z + '\n' +
'Timestamp: ' + acceleration.timestamp + '\n');
stopAccelerationWatch()
chooseButtonsForCard();
drawScreen();
startAccelerationWatch();
}
}
// onError: Failed to get the acceleration
//
function onError() {
alert('onError!');
}
Search WWH ::




Custom Search