Overview

The accelerometer sample application demonstrates how you can gather values from the accelerometer in a BlackBerry® device that has an accelerometer. You can then apply the values to move an image of a ball on the screen of the BlackBerry device.

By holding the BlackBerry device parallel to the ground and tilting it in any direction, the image of the ball moves by reacting to the force of gravity and the programmatically defined coefficient of friction. This process simulates a ball rolling around a tilting table. When the ball hits the edge of the screen, the ball bounces off the edge as if it were a barrier.

In addition to demonstrating how to gather data from the BlackBerry device's accelerometer, the sample application also provides some basic gravity-simulating algorithms that you might find useful when you develop gravity-based games.

If the BlackBerry device that is running the sample application does not have an accelerometer, the sample application displays a dialog box with the message "This device does not support accelerometer." and the sample application closes.

However, if the BlackBerry® Smartphone Simulator is running the sample application, the sample application generates random accelerometer readings to simulate someone tilting the BlackBerry device.

Next topic: Featured classes

Was this information helpful? Send us your comments.