O'Reilly logo

Professional HTML5 Mobile Game Development by Pascal Rettig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Figure 24-1: The final device orientation example.

c24f001.tif

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required