| Reply | « Previous Thread | Next Thread » |
|
I am writing a j2me RPG game, in the main loop, I wrote a Keypress() function.
private void keyPressed() { int keyStates = getKeyStates(); // Left if ((keyStates & LEFT_PRESSED) != 0) { pointer move once. .......... } } \\ something like this. when I press left (4) key. the pointer in game always move twice. It seems main thread accept key event too sensitive, even I press and release very quickly. we definetly do not want to these key make us crazy. Does anyone can help me out ? Thanks |
|
Well for the keypressed being called twice it might be due to the keyReleased() try removing it.
As for slowing the reponse of keypressed you can do something like this long current =System.currentTimeMillis(); long gap ;//set this as per your choice private void keyPressed() { if(System.currentTimeMillis()-current<gap) { return; } current =System.currentTimeMillis(); int keyStates = getKeyStates(); // Left if ((keyStates & LEFT_PRESSED) != 0) { pointer move once. .......... } } \\ something like this. |
| surinderpalkundal |
| View Public Profile |
| Find all posts by surinderpalkundal |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|