Game Development Reference
In-Depth Information
interval in milliseconds by calling setRequestedUpdateInterval on
the Accelerometer instance and passing it a value. In general, how-
ever, you probably won
t want to use anything faster than the
default interval, and more frequently you start using up extra bat-
tery life
something users of your games won
t appreciate. In fact,
if you find you can, it
s not a bad idea to reduce the frequency of
intervals as it mean that you
re polling the device even less and in
fact saving battery power.
When you receive an AccelerometerEvent, you
ll find that it has
four distinct values inside. The first three are the x , y ,and z values
for the acceleration along each of those respective axes. Each of
these properties ranges from around
approximately 9.8 m/s 2 ), cumulatively representing the orientation
of the device and the forces of acceleration due to gravity. When
the device is moved or rotated, these values fluctuate, reflecting the
acceleration applied to the device at given angles. We
1 G to +1 G (a
ll look at a
visual representation of this concept momentarily. The fourth value
is a timestamp identifying the number of milliseconds since the
application started when the event was created. You can think of it
as though getTimer was called when the event occurred. This data
might be useful if you wanted to delay or ignore reaction to an
AccelerometerEvent without messing with the update interval.
How Accelerometer Values Are Computed
When an iPhone or other mobile device is stationary, the values
from AccelerometerEvents are consistent as they represent the
force of gravity acting downwards on it. Figure 15.2 shows the
three axes that are used to determine the orientation of an iPhone
Figure 15.2 The three axes of
the iPhone ' s accelerometer.
Search Nedrilad ::

Custom Search