Game Development Reference
In-Depth Information
Other sensors
In this section we'll take a look at the other sensors available in Windows 8 that can be
useful for games. Whether they are used in conjunction with the other sensors or by
themselves, these sensors can provide valuable data about the physical world. This
context can be used for games that augment the world around the player and intro-
duce new gameplay concepts that may not have been done before.
Light
One of the other sensors available for use is the light sensor. The light sensor is avail-
able on most tablet devices and provides an illuminance value that is usually used to
adjust the screen brightness; however, any app or game can take advantage of this
to provide different functionality. For example, a mapping application may use the il-
luminance value to determine if the phone is in sunlight and provides a different style
of map that is easier to see. This could be done by games that use maps as well, or
you might make a horror game that reacts to the light around the player, increasing
immersion.
To set up the LightSensor object we will do the same thing as all of the previous
sensors; we call the LightSensor::GetDefault() method and check if it exists
by checking the returned value for a null pointer.
Assuming we have the sensor, we can retrieve the values using the event system
by registering a TypedEventHandler that has a LightSensor and
LightSensorReadingChangedEventArgs for its template arguments.
If we want to use the polling method, it's a simple matter of calling the GetCur-
rentReading() method when we need the data and making use of the data stored
in the provided LightSensorReading object.
The LightSensorReading object provides us with two values, one for the
timestamp included with all of the other readings, and one called Illuminan-
ceInLux , which is a float that stores the lux reading.
Lux is a unit of measurement of the amount of visible light. As a reference, you can
expect the indoor lighting to be of approximately 500 lux, while direct sunlight can be
Search WWH ::




Custom Search