|
Tips & Tricks
Need some quick tips? In this issue, get more tips on making your game more robust.
Learn how to add Vibration and Sound to your game. This issue's tip comes from the January 2005 issue of the Developer Journal.
With the use of the Alert class (net.rim.device.api.system.Alert), audio and vibration alerts can easily be added to your game.
The vibration alert will vibrate the device for the specified number of milliseconds, up to a maximum of 25,500. The vibration can also be stopped programmatically; cutting short the duration specified if another action is taken.
//Vibrate for 75 milliseconds. Alert.startVibrate(75);
Creating a sound alert involves two steps.
First, an array of shorts must be created. This will be passed to the audio alert method along with an integer that represents the volume level that ranges from 1 (softest) to 100 (loudest). This array defines the nature of the sound that will be played. The array is made up of pairs of values that represent the frequency and duration of a sound. The first value represents the frequency of the note that will be played and the second value represents its duration. Building the array to contain multiple pairs allows you to create a custom tune for your application. For example:
short[] explodeAudio = { 300, 50, 500, 50, 300, 50, 500, 50, 300, 50 );
The second step is to play the sound:
Alert.playBuzzer(explodeAudio, 100);
Alerts can also be stopped at any point in time. This can allow you to play a long alert and then interrupt it when a certain action takes place. The stop methods are called to stop vibration or audio alerts.
//Stop Audio Alert Alert.stopAudio(); //Stop Vibrate Alert Alert.stopVibrate();
Got a tip you want to share? Share it by emailing developernewsletter@rim.com
Back to top
|