J2ME - MIDP 2.0 - Gamecanvas.getKeyStates();

S

Stefan Reiter

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
 
S

Stefan Reiter

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
..
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top