HTML and CSS Reference
In-Depth Information
Adding in an iPhone “Gesture”
The PhoneGap API allows us to add in control over various iOS features, such as vibrate,
geolocation, and accelerometer. We will target one of these features by adding code
that will wipe our board clean and create a fresh new game when the phone is shaken.
To do this, we will look for changes to the device's physical location in space (using
JavaScript), and then simply call our existing chooseButtonsForCard() and
drawScreen() functions to refresh the card.
First, we need to add a single line to the chooseButtonsForCard() function that will set
all the buttons instances' press attributes to false :
function chooseButtonsForCard(){
//copy jargon into temp array
var tempArray = [];
for (var arrayctr=0;arrayctr<standardJargonList.length;arrayctr++){
for (var ctr1=0;ctr1<buttons.length;ctr1++){
for (var ctr2=0; ctr2<buttons[ctr1].length;ctr2++){
var randInt = Math.floor(Math.random()*tempArray.length)
buttons[ctr1][ctr2].text = tempArray[randInt];
buttons[ctr1][ctr2].press = false;
Next, we need to add a function that will listen for the iOS “shake” event, and then
refresh the card.
Apple makes it pretty easy to test for changes in the x , y , and z coordinate spaces of an
iOS device (and PhoneGap makes it even easier), but acting on this information is a
little tricky and will require the use of an actual device for testing.
At the time of this writing, a PhoneGap Adobe AIR iPhone simulator
was available that goes beyond the limited shake gestures available in
the SDK simulator. If you do not have a device to test with, we recom-
mend trying this emulator. It can be found at
yohei/2009/04/01/phonegap-air-simulator-in-development/ .
Adding the Gesture Functions to index.html
Inside the canvasApp() function, we will need to add a series of functions and a variable
to use in testing the iPhone's accelerometer, which detects movement in our
Search WWH ::

Custom Search