Game Development Reference
In-Depth Information
ing itself is pretty simple; the class has the following properties that you can use to
get the information you need:
property double AccelerationX;
property double AccelerationY;
property double AccelerationZ;
property Windows::Foundation::DateTime
Timestamp;
Just read the values directly out of the
Reading
object to get the information you
need.
When you're done, just remove your event handler from the
ReadingChanged
event (keep the token you get when you set the handler) and set the
ReportIn-
terval
to
0
, which notifies Windows that the resources can be released.
As you can see, this is really simple; let's take a look at what you need to do to poll
for these events, in case you want the game play to be controlled by the accelero-
meter function.
To poll for the values we still need to get the default accelerometer and set up the
ReportInterval
as we did earlier; however, instead of setting an event to retrieve
the reading, we will call the following function:
auto reading =
accelerometer->GetCurrentReading();
This will give us the last reading (based on the
ReportInterval
) that Windows
has in an
AccelerometerReading
object. This is exactly the same class that
is provided by the
Reading
property inside
AccelerometerReadin-
gChangedEventArts
. Ensure that you check if your reading is null before trying to
access it, as if there is an issue with the accelerometer you may not receive a read-
ing.