Game Development Reference
In-Depth Information
and more fine-tuned way is to access the orientation data of these sensors directly through the
UIAccelerometer
class. Let's take a look at the shaking example first.
Responding a to Motion Event (Shaking)
Whenever an
iOS
device is shaken, a motion event is generated for the application to consume.
Personally, I find using the shake in an application to be super annoying; however, some people think
it is a good idea, so let's look at how we can take advantage of this feature. Figure
8-8
shows our
example.
Figure 8-8.
Asteroids breaking apart from a device shake
In Figure
8-8
, we see a number of asteroids. These asteroids used to be a single asteroid, but a few
shake events caused it to break apart. The class for this example is called
ShakeController
and
extends
GameController
. There is nothing particularly interesting about its header file, so let's just
jump to its
doSetup
task, shown in Listing 8-30.