J2ME - MIDP 2.0 - Gamecanvas.getKeyStates();

Discussion in 'Java' started by Stefan Reiter, May 28, 2005.

  1. Hi,

    I am working on a little game in J2ME MIDP 2.0.

    The player (a sprite) is moving very slowly -
    it seems like that it doesn't recognize all buttons that have been
    pressed - if I put the thread to sleep for 500 milliseconds,
    it does recognize all buttons pressed correctly, but of course
    this doesn't speed up the movement of the sprite because
    then it always waits half a second for the next move.
    That's how my method looks like:

    int keyState = getKeyStates();

    if ((keyState & LEFT_PRESSED) != 0) {
    // This animates the sprite
    player.createAnimation(LEFT_PRESSED);
    this.movePlayer(LEFT_PRESSED);
    }
    } else if ((keyState & RIGHT_PRESSED) != 0) {
    // This animates the sprite
    player.createAnimation(RIGHT_PRESSED);
    this.movePlayer(RIGHT_PRESSED);
    } else if ((keyState & UP_PRESSED) != 0) {

    and so on...

    What's wrong here? Any ideas?

    Thanks,

    Stefan
     
    Stefan Reiter, May 28, 2005
    #1
    1. Advertising

  2. Update:

    I put super(false) in my GameCanvas Constructor and
    implemented the keyPressed and keyReleased methods.
    Now it works perfectly.

    Any idea why this works but working with
    int keyStates = getKeyStates();

    does not work properly???

    Now it looks more or less like this:

    public void run {
    ... // unimportant stuff
    ..
     
    Stefan Reiter, May 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nishadixit
    Replies:
    5
    Views:
    1,262
    Joe Discar
    Jun 1, 2005
  2. Fahad
    Replies:
    1
    Views:
    591
    Andrew Thompson
    Aug 8, 2005
  3. Jeff

    newbie: getKeyStates()

    Jeff, Dec 22, 2005, in forum: Java
    Replies:
    2
    Views:
    2,438
  4. Jeff

    GameCanvas & menu, how?

    Jeff, Jan 1, 2006, in forum: Java
    Replies:
    0
    Views:
    1,154
  5. Jeff
    Replies:
    0
    Views:
    575
Loading...

Share This Page