Game Development Reference
In-Depth Information
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 saves
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 empty file tells 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 5-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 want 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 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 uses 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.
OnStartMusic(String name, int loop) : This fires on background music.
It delegates to the receiver.
 
Search WWH ::




Custom Search