Trying Out Device Orientation
To try out the device orientation events, you can build a quick demonstration using the SVG and physics code from Chapter 14, “Building Games with SVG and Physics.” Figure 24-1 shows the end result.
The demonstration consists of a set of static walls enclosing a set of balls that can react to gravity. Gravity always stays consistent with reality, but as you rotate the device, gravity changes relative to it, which will cause the balls to fly around the screen.
Creating a Ball Playground
To start, create a new HTML file called orient.html with the contents of Listing 24-1. You need a number of quintus files and the engine’s dependencies along with Box2dWeb-2.1.a.3.js from Chapter 14.
Listing 24-1: The orientation example HTML file
<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"/> <title>DeviceOrientation</title> <script src='js/jquery.min.js'></script> <script src='js/underscore.js'></script> <script src='js/Box2dWeb-2.1.a.3.js'></script> <script src='js/quintus.js'></script> <script src='js/quintus_input.js'></script> <script src='js/quintus_sprites.js'></script> <script src='js/quintus_scenes.js'></script> <script src='js/quintus_physics.js'></script> <script src='js/quintus_svg.js'></script> ...
Get Professional HTML5 Mobile Game Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.