Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > J2ME - MIDP 2.0 - Gamecanvas.getKeyStates();

Reply
Thread Tools

J2ME - MIDP 2.0 - Gamecanvas.getKeyStates();

 
 
Stefan Reiter
Guest
Posts: n/a
 
      05-28-2005
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
 
Reply With Quote
 
 
 
 
Stefan Reiter
Guest
Posts: n/a
 
      05-28-2005
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
..
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
J2ME, MIDP 2.0 and detecting phone number Vagif Abilov Java 12 08-21-2006 07:48 PM
java.lang.NullPointerException at com.sun.kvem.midp.MIDP.run(MIDP.java:651) Fahad Java 1 08-08-2005 02:11 PM
Will application J2ME MIDP 2.0 based of one device run another J2ME MIDP 2.0 device? nishadixit Java 5 06-01-2005 05:40 AM
J2ME MMAPI's for MIDP 1.0? Jeremy Deats' Java 1 06-23-2004 03:20 PM
[J2ME] views wanted for new MIDP-developer site idea DigiAl Java 17 06-21-2004 07:03 PM



Advertisments