[Design Guidelines - General Introduction]
[Design Guidelines - Technical Overview]
Contents
- Problem Description
- Solution Description
- List of Affected Devices
- Keywords
1. Problem Description
How to use key events, how to assign different game keys than the default supported by the device for a specific application need
Any application that uses canvas and handles Low-Level Events
2. Solution Description
All devices and platforms
SUBJECTIVE - Use JAD file to define different game keys to key codes
Solution description:
1. Define keycodes in JAD file [example]
Defining specific key mapping for the MIDlet/Device, which is not dependent on the default key mapping of the device implementation
1.1 Read keycodes from JAD file [example]
1.2 Map keycodes to game keys [example]
1.3 handle key events in Canvas [example]
None.
Example for defining keys in JAD file
...
UP: 2
DOWN: 8
LEFT: 4
RIGHT: 6
FIRE: 5
...
|
Example for reading the key mapping form the JAD file
...
/* This code can be called anywhere in the application */
//Get User-Defined attribute from JAD
int upKeyCode = 0;
String codeStr = getAppProperty("UP");
try {
upKeyCode = Integer.parseInt(codeStr);
} catch (NumberFormatException nfe) {
}
...
|
Example for mapping keycodes to game keys
...
public int myGetGameAction(int keyCode) {
if (keyCode == upKeyCode) {
return Canvas.UP;
}
...
}
...
|
Example for handling key events in Canvas
...
public void keyPressed(int keyCode){
if(myGetGameAction(keyCode)==LEFT){
...
} else if(myGetGameAction(keyCode)==RIGHT){
...
} else if(myGetGameAction(keyCode)==FIRE) {
...
} else if(myGetGameAction(keyCode)==UP) {
...
}
...
|
3. List of Affected Devices
All devices
4. Keywords
events, key code, game action
Copyright 2006 Sun Microsystems, Inc. and Orange SA All Rights Reserved.
|