Motorola J2ME Specifications Page 41

  • Download
  • Add to my manuals
  • Print
  • Page
    / 86
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 40
8
Gaming API and Sound
41
public static final int VOLUME_MIN - The minimum volume for
playing sound effects. This constant has a value of 0.
GameScreen Methods
The GameScreen class defines the following methods:
protected Graphics getGraphics() - Obtains the Graphics object for
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() - Gets the states of the physical keys. Each bit
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 public int
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) - Enables or
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
Page view 40
1 2 ... 36 37 38 39 40 41 42 43 44 45 46 ... 85 86

Comments to this Manuals

No comments