Game Development Reference
In-Depth Information
This will give us the default accelerometer, ready for use. If no accelerometer exists,
we'll get a nullptr value, which should be handled before anything happens.
Once you have the accelerometer, you need to set a reporting interval that fits your
needs. The reporting interval defines the amount of time between each update
of the accelerometer values. With this we can increase or reduce the frequency
of the updates and, if we're using events for data retrieval, we can adjust how
frequently they occur. The accelerometer will have a minimum reporting interval,
so use that information when deciding on your reporting interval by checking the
accelerometer->MinimumReportInterval . Once you've decided on the inter-
val, you can set it with the following line of code:
accelerometer->ReportInterval =
desiredReportInterval;
Now all that you need to do is register an event handler for the accelerometer-
>ReadingChanged event, as follows:
accelerometer->ReadingChanged::add(
ref new TypedEventHandler<
Accelerometer^,
AccelerometerReadingChangedEventArgs^>
(
this,
&MyClass::ReadingChanged
));
This particular event can be set with a TypedEventHandler that has the Accel-
erometer and AccelerometerReadingChangedEventArgs parameters.
Now you need the event handler method, and in this case we've named it Readin-
gChanged . The event system provides access to the Accelerometer object, as
well as the event arguments, which contain the readings for that event, and this is
the object you need to use to get the values you want.
AccelerometerReadingChangedEventArgs is a simple class that contains a
single property named Reading , which is an AccelerometerReading . The read-
Search WWH ::




Custom Search