HTML and CSS Reference
In-Depth Information
Because of the slightly different approach in setting the velocity—with mouse events
you're aiming at a target; with orientation events you're linking the velocity directly to the
angle—the update_xy() function in the wilson object also needs updating. The fol-
lowing listing has the code.
Listing I.27. Update Wilson's X and Y positions
Future improvements: lockOrientation
If you play with this example on your mobile device, you'll probably notice a minor annoy-
ance: Everything is set up assuming landscape mode, but as you rotate the device, it's very
easy to flip the orientation to portrait mode. At the moment your only option is to detect
the orientation change and adjust your code to deal with both portrait and landscape modes.
But plans are afoot to provide web apps with the same ability to lock orientation that native
apps get. Unfortunately, experimental implementations aren't yet available.
I.3.5. The Vibration API: accessing a mobile device's vibration function
Mobile devices offer alternative methods for feedback as well as the alternative methods
for input you looked at in the preceding sections. The Vibration API is a proposal from
Mozilla to provide access to a mobile's built-in vibration function. You can adapt the ex-
ample from section I.3.3 to vibrate when Wilson hits the edges of the screen by adjusting
the update_xy() function again, as shown in the next listing.
Vibration API
Search WWH ::

Custom Search