I. Game Development Strategy 1 Game Action The use of MIDP's Canvas classes allow programmers to handle some button events, or as a specific low key code event or as an abstract game action. Fullcanvas is a full-screen dragcaas class in Nokia, which is inherited from the Canvas class. In a game of round, there is no more than four arrow keys (upper, lower, left, right) games, it is best to control the game action using a direct keyboard code. Game examples that can be used with abstract games include chess and knowledge tests and puzzle games, which are used to scroll or move with the arrow keys. Game action should only be used only in a game that does not require a quick response. This is because the game action mapping of the selected device may not apply to the game that requires fast action. And, if a game requires a direction button or this game is a fast-paced action game, then the player needs to move the game character, and the other hand needs to perform other operations, such as shooting, opening, etc., then Just use the direct keyboard code. The reason is that there is no oblique game action in the MIDP, and the game action mapping is designed for one hand. When using the direct keyboard code event, you must pay special attention to the portability of the application. There is a great difference between the layout of the keyboard between different devices. Developers can solve this problem by allowing users to define keywords in the game. This can be done before the game begins or in the "Options" page of the game. Keyboard code and game movements should not be mixed in the same application. 2 Description of the game action A MIDlet application detects the abstract game action in which keyboard code maps to the running application by calling the Canvas method:
Public Static Int getGameAction (int keycode);
CANVAS class defines an abstract game action set: Up, Down, Left, Right, Fire, etc. Game developers should know a question in the MIDP 1.0 specification. This class defines the method of transforming the keyboard code to the game action, and also defines the way to convert the game action to the keyboard code.
Public int getGameAction (int keycode) public int getKeyCode (int gameAdition): 0000-00-00 PUBLIC INT GetKeycode
Method GetKeyCode (int gameAction) may result in some problems because it can only return a keyboard code based on the game action, even if the MIDP 1.0 allows more than one keyboard code is implemented. In the Nokia phone, individual keyboard code is mapped to the same game action, such as "UP" and "2 keys" are mapped to upward game action. This method can only return one of them; the returned value is a specific implementation. However, if the method getGameAction (int keycode) uses the "UP" and "2 key" keyboard code as a parameter, this method will return the correct upward game action. Let's take a bad example to deepen our impression:
// bad example, do not do it: class TetrisCanvas extends Canvas {int leftKey, rightKey, downKey, rotateKey; void init () {// FOLLOWING MUST NOT BE DONEleftKey = getKeyCode (LEFT); rightKey = getKeyCode (RIGHT); downKey = getKeyCode (DOWN); rotateKey = getKeyCode (FIRE);} public void keyPressed (int keyCode) {if (keyCode == leftKey) {moveBlockLeft ();} else if (keyCode = rightKey) {...}}}
Here is a better solution:
class TetrisCanvas extends Canvas {void init () {} public void keyPressed (int keyCode) {int action = getGameAction (keyCode); switch (action) {case Canvas.LEFT: moveBlockLeft (); break; case Canvas.RIGHT: moveBlockRight ( Break;}}}}
This example is an example in the MIDP 1.0 specification. Use the getKeyCode (int gameAction) to process the keyboard code value, only one value can be returned. If so, other possible button mapping cannot be used in the MIDLET. For example, there will be problems in NOKIA 7650, and Nokia 7650 has five arrow keys and a joystick and a normal keyboard layout. The above example will return the value of the joystick rather than the value of the keyboard. This is a method of processing an event with an apparatus, and is also a bad method. A better solution is to use getGameAction (int keycode) within the keypressed () method. Typically, applications should avoid using the getKeyCode (int gameAction) method and always using getGameAction.
Author: wayne compile posted from: yesky.com
Author Blog:
http://blog.9cbs.neet/mobilechannel/