Game Development Reference
In-Depth Information
stopMusic (String key) : This method stops the background music given by key .
setMusicVolume (int vol) : This method sets the background music volume. vol
ranges from 0 to 100.
The AudioClip class is the same as Wolfenstein 3D's AudioClip (shown in the previous chapter). The
only difference is that the package has been renamed.
Because the audio files (including background music) can occupy more than 5MB, files have been
packed in a zip archive and installed at runtime into the SD card. This will save precious disk space in
the main file system. The zip archive lives in the assets folder of the Doom project.
Tip Android features an automated media scanner service that searches for audio files within the file system.
This can be really annoying, as your media player will suddenly display a few hundred unwanted Doom sounds
and music. You can fix the problem by adding an empty file called .nomedia to the sound folder. This will tell the
media scanner to bypass this directory.
Native Interface Class
The native interface class is the two-way pipe that sends messages from Java to the Doom engine
through native methods, and from the engine to Java using C to Java callbacks (see Listing 7-12). This
class consists of three parts: callback listener, native methods, and C to Java callbacks.
Callback Listener
The callback listener is implemented by the interface EventListener . It must be implemented by clients
that wish to receive C to Java callbacks (in this case, by the main activity DoomClient.java ). The C to Java
callbacks are as follows:
OnMessage(String text, int level) : This is mostly a debug callback that sends
messages to let Java know what is happening on the native side.
OnInitGraphics(int w, int h) : This is the very first callback and fires only once
after graphics initialization. It tells Java the width and height of the video buffer.
OnImageUpdate(int[] pixels) : This fires many times per second and sends an
Android packed video buffer to Java, which will use it to render the game bitmap.
OnFatalError(String text) : This callback fires when there is an unrecoverable
error in the engine. The receiver should display the message and terminate.
OnQuit(int code) : This callback fires when the user exits the game. It sends a
return code back to the receiver.
OnStartSound(String name, int vol) : This fires when the native engine starts a
sound. It delegates to the receiver.
Search WWH ::




Custom Search