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


© 2005 Research In Motion Limited. All rights reserved. The BlackBerry and RIM families of related marks, images and symbols are the exclusive properties and trademarks of Research In Motion Limited. RIM, Research In Motion, ‘Always On, Always Connected’ and BlackBerry are registered with the U.S. Patent and Trademark Office and may be pending or registered in other countries. All other brands, product names, company names, trademarks and service marks are the properties of their respective owners. The specifications and features contained in this document are subject to change without notice. All other brands, product names, company names, trademarks and service marks are the properties of their respective owners. Prices subject to change without notice. Research In Motion Limited presents information about third party products and services on BlackBerry Connection for your information. However, since Research In Motion Limited relies on information provided by outside sources, it makes no warranty or guarantee concerning the features, reliability or pricing of third party products or services, or their compatibility with any Research In Motion Limited products. Research In Motion Limited, 295 Phillip Street, Waterloo, Ontario, Canada N2L 3W8