×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    2

    How to implement getKeyStates() on MIDP1.0??

    I am programming a game on MIDP1.0.
    It requires 2 keys pressed at the same time,but there is no method in MIDP1.0 which can detect 2 keys at the same time.
    Help!!

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    You have to set flags in the keyPressed() method and reset them in the keyReleased() method, and poll those flags in your game loop:
    Code:
    boolean upPressed;
    boolean leftPressed;
    void keyPressed(int code) {
      int action = getGameAction(code);
      if (action == UP) upPressed = true;
      // same for the rest of the keys you need
    }
    void keyReleased(int code) {
      int action = getGameAction(code);
      if (action == UP) upPressed = false;
      // same for the rest of the keys you need
    }
    // one tick of the game loop:
    void tick() {
      if (upPressed && leftPressed) moveDiagonally();
      // ...
    }
    Not all phones support multiple keypresses though, so the keyPressed() might not get called for the second key, and in that case there is nothing you can do.

    shmoove

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    2
    Thank u very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •