Motorola J2ME Specifications Page 55

  • Download
  • Add to my manuals
  • Print
  • Page
    / 86
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 54
8
Gaming API and Sound
55
SoundEffect Class
The SoundEffect class encapsulates the data for a game sound effect. A game may
create several
SoundEffect objects, one for each of the sounds that it needs to play.
The sound data may be stored on the device as a named resource in the application JAR
file, or it can be stored on a server and retrieved via the network.
SoundEffect
instances are played by a
GameScreen.
SoundEffect Methods
The SoundEffect class implements the following method:
public static SoundEffect
createSoundEffect(String resource) throws
FileFormatNotSupportedException – Creates a
SoundEffect for
the sound data stored in the specified named resource or URL. The data must be in a
sound format that is supported by the device. Though additional formats may be
supported, all devices must support some format yet to be determined.
Using SoundEffect
As described above, a game can need several different sound effects. The code below
exemplifies the creation of some
SoundEffect objects:
The following is a code sample to show the creation of
SoundEffect objects:
SoundEffect Objects
try{
// Create a SoundEffect using a wave file inside the JAR
SoundEffect s1 = createSoundEffect("/jump.wav");
// Create a SoundEffect using a wave located
// on a web site
SoundEffect s2=
createSoundEffect("http://www.motorola.com/sound/mp.wav");
}catch(FileFormatNotSupportedException fe){}
Sprite Class
The Sprite class is used to create graphic images, animated or non-animated, that a
user can interact with and move around.
Page view 54
1 2 ... 50 51 52 53 54 55 56 57 58 59 60 ... 85 86

Comments to this Manuals

No comments