Java Reference
In-Depth Information
public void startApp() {
initialize();
}
public void pauseApp() {
canvas.setPaused(true);
}
public void destroyApp(boolean unconditional) {
canvas=null;
getDisplay().setCurrent(null);
}
}
This is straightforward code, especially if you already understand the life cycle of a
MIDlet. The only other work this MIDlet class does is in pauseApp , where the MIDlet
instructs the game canvas to pause game play by setting the game pause state to true .
Game play is resumed when the MIDlet receives a new startApp invocation; if the game
canvas already exists, the application will resume game play by setting the game pause
state to false .
Implementing the Game Canvas
If the SpriteSampleMIDlet class is simple, the game canvas is only a little more complicated.
This is due to the work in setting up the visible layers and the game loop. Listing 8-11 shows
the SpriteCanvas class that extends the GameCanvas class and implements the game canvas
and loop.
Listing 8-11. The SpriteCanvas Class
package com.apress.rischpater;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import java.io.IOException;
import java.util.Random;
public class SpriteCanvas
extends GameCanvas
implements Runnable {
 
Search WWH ::




Custom Search