|
BenQ Mobile |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.microedition.lcdui.Displayable
javax.microedition.lcdui.Canvas
javax.microedition.lcdui.game.GameCanvas
This class is a subclass of LCDUI’s Canvas and provides the basic ’screen’ functionality for a game. In addition to the methods inherited from Canvas, this class also provides game-centric features such the ability to query the current state of the game keys and synchronous graphics flushing; these features simplify game development and improve performance.
Field Summary | |
static int |
DOWN_PRESSED
|
static int |
FIRE_PRESSED
|
static int |
GAME_A_PRESSED
|
static int |
GAME_B_PRESSED
|
static int |
GAME_C_PRESSED
|
static int |
GAME_D_PRESSED
|
static int |
LEFT_PRESSED
|
static int |
RIGHT_PRESSED
|
static int |
UP_PRESSED
|
Fields inherited from class javax.microedition.lcdui.Canvas |
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP |
Constructor Summary | |
protected |
GameCanvas(boolean suppressKeyEvents)
Creates a new instance of a GameCanvas. |
Method Summary | |
void |
flushGraphics()
Flushes the entire off-screen buffer to the display. |
void |
flushGraphics(int x,
int y,
int width,
int height)
Flushes the specified region of the off-screen buffer to the display. |
protected Graphics |
getGraphics()
Obtains the Graphics object for rendering a GameCanvas. |
int |
getKeyStates()
Gets the states of the physical game keys. |
protected void |
keyPressed(int keyCode)
Called when a key is pressed. |
protected void |
keyRepeated(int keyCode)
Called when a key is repeated (held down). |
void |
paint(Graphics g)
Paints this GameCanvas. |
Methods inherited from class javax.microedition.lcdui.Canvas |
getGameAction, getHeight, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, keyReleased, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, setFullScreenMode, showNotify, sizeChanged |
Methods inherited from class javax.microedition.lcdui.Displayable |
addCommand, getTicker, getTitle, getWidth, isShown, removeCommand, setCommandListener, setTicker, setTitle |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int UP_PRESSED
public static final int DOWN_PRESSED
public static final int LEFT_PRESSED
public static final int RIGHT_PRESSED
public static final int FIRE_PRESSED
public static final int GAME_A_PRESSED
public static final int GAME_B_PRESSED
public static final int GAME_C_PRESSED
public static final int GAME_D_PRESSED
Constructor Detail |
protected GameCanvas(boolean suppressKeyEvents)
If requested, key event suppression for a given GameCanvas is started when it is shown (i.e. when show- Notify is called) and stopped when it is hidden (i.e. when hideNotify is called). Since the showing and hiding of screens is serialized with the event queue, this arrangement ensures that the suppression effects only those key events intended for the corresponding GameCanvas. Thus, if keys are being generated while another screen is still shown, those key events will continue to be queued and dispatched until that screen is hidden and the GameCanvas has replaced it.
Note that key events can be suppressed only for the defined game keys (UP, DOWN, FIRE, etc.); key events are always generated for all other keys.
suppressKeyEvents
- True to suppress the regular key event mechanism
for game keys, otherwise false.
java.lang.OutOfMemoryError
- if there is insufficient memory available to create this GameCanvas and its off-screen buffer.Method Detail |
public void flushGraphics()
If the specified region extends beyond the bounds of the buffer, only the intersecting region is flushed. This method does nothing and returns immediately if the GameCanvas is not currently shown or the flush request cannot be honored for some reason.
public void flushGraphics(int x, int y, int width, int height)
If the specified region extends beyond the bounds of the buffer, only the intersecting region is flushed. This method does nothing and returns immediately if the GameCanvas is not currently shown or the flush request cannot be honored for some reason.
x
- The left edge of the region to be flushedy
- The top edge of the region to be flushedwidth
- The width of the region to be flushedheight
- The height of the region to be flushedprotected Graphics getGraphics()
A unique buffer is provided for each GameCanvas instance. Therefore, in the interests of minimizing heap usage, it is preferable to re-use a single GameCanvas instance instead of creating numerous instances.
A new Graphics object is created and returned each time this method is called; therfore, the needed Graphics object(s) should be obtained before the game starts then re-used while the game is running. For each GameCanvas instance, all of the provided graphics object will render to the same off-screen buffer.
public int getKeyStates()
The lower bits are defined by UP_KEY, DOWN_KEY, LEFT_KEY, etc.; the remaining bits may be optionally mapped to device-specific keys.
For example
-
// Get the key state and store it
-
int keyState = getKeyStates();
if ((keyState & LEFT_KEY) != 0)
{
positionX--;
}
-
protected void keyPressed(int keyCode)
keyPressed
in class Canvas
keyCode
- The key code of the key that was pressed.protected void keyRepeated(int keyCode)
keyRepeated
in class Canvas
keyCode
- The key code of the key that was repeated.Canvas.hasRepeatEvents()
public void paint(Graphics g)
paint
in class Canvas
g
- The Graphics object with which to render the screen.
|
BenQ Mobile |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2006 BenQ Mobile GmbH & Co. OHG or respective copyright owner. All Rights Reserved. BenQ Corp. is a trademark licensee of Siemens AG. |
For further information about Mobility Toolkit (MTK) visit our Developer Portal. |