Java Reference
In-Depth Information
2.3.6 Game API
The MIDP specification supports easy game development through the use
of the javax.microedition.lcdui.game package. It contains the
following classes:
GameCanvas
LayerManager
Layer
Sprite
TiledLayer .
The aim of the API is to facilitate richer gaming content through a set
of APIs that provides useful functionality.
GameCanvas
A basic game user interface class that extends javax.microedition.
lcdui.Canvas , GameCanvas provides an offscreen buffer as part of
the implementation even if the underlying device doesn't support double
buffering. The Graphics object obtained from the getGraphics()
method is used to draw to the screen buffer. The contents of the screen
buffer can then be rendered to the display synchronously by calling the
flushGraphics() method. The GameCanvas class also provides the
ability to query key states and return an integer value in which each bit
represents the state of a specific key on the device:
public int getKeyStates();
If the bit representing a key is set to 1, then this key has been pressed
at least once since the last invocation of the method. The returned integer
can be ANDed against a set of predefined constants, each representing
a specific key, by having the appropriate bit set (support for the last four
values is optional).
We use the GameCanvas class members that describe key presses
(e.g., GameCanvas.FIRE_PRESSED ) to ascertain the state of a key in
the manner shown below:
if ( getKeyStates() & Game.Canvas.FIRE_PRESSED != 0 ) {
// FIRE key is down or has been pressed - take appropriate action
}
Search WWH ::




Custom Search