Gamescreen Methods - Motorola C370 Series Technical Manual

J2me developer guide
Hide thumbs Also See for C370 Series:
Table of Contents

Advertisement

8
Gaming API and Sound
public static final int VOLUME_MIN
playing sound effects. This constant has a value of 0.

GameScreen Methods

The
GameScreen
protected Graphics getGraphics()
rendering GameScreens. The Graphics object renders to an off-screen buffer whose
size is equal to that of the GameScreen (use getWidth() and getHeight() to determine
the size of the GameScreen). The buffer is initially filled with white pixels. Rendering
operations do not appear on the display until flushGraphics() is called; flushing the
buffer does not change its contents (that is, the pixels are not cleared as a result of
the flushing operation). Only one image buffer is supported because without a
vertical sync blanking period or its equivalent, there is little or no benefit from having
multiple image buffers. Only one Graphics object exists for each GameScreen
instance.
public int getKeyStates()
in the returned integer represents a specific key on the device. A key's bit will be set if
the key is currently pressed or was pressed at least once since the last time this
method was called. The bit will be 0 if the key is not currently pressed and was not
pressed at all since the last time this method was called. This latching behavior
ensures that a rapid key press and release will always be caught by the game loop,
regardless of how slowly the loop runs. This method may be called twice to check if a
key is currently pressed; that is, calling this method twice effectively disables the
latching behavior. The lower bits are defined by UP_KEY, DOWN_KEY, LEFT_KEY,
etc.; the remaining bits may be mapped to device-specific keys.
The following is a code sample to show implementation of
getKeyStates()
Public int getKeyStates ()
// Get the key state and store it
int keyState = gameScreenObject.getKeyStates();
if ((keyState & LEFT_KEY) != 0) {
positionX--;
} else if ((keyState & RIGHT_KEY) != 0) {
positionX++;
}
public void enableKeyEvents(boolean enabled)
disables key event calls to this GameScreen. If disabled, the Canvas key event
methods (keyPressed, keyRepeated, keyReleased) are not called when keys are
pressed or released; however, the developer can still call getKeyStates to query the
state of the keys. For games that poll key state and do not need event-driven key
class defines the following methods:
- Gets the states of the physical keys. Each bit
:
- The minimum volume for
- Obtains the Graphics object for
public int
- Enables or
41

Advertisement

Table of Contents
loading

This manual is also suitable for:

C450 seriesC550 series

Table of Contents