keyPressed() delay on some phones

Started by
5 comments, last by shmoove 18 years, 8 months ago
hello there! On a Samsung C225 phone (midp 2.0) if I press quick enough the keys I introduce a delay between the moment I actually press the button and the application receives a keyPressed(keyCode) event. The game fps remains the same (around 7-9 fps) but the delay continue to increases after play time (my tester obtained around 30 seconds last time!!!). If I press more keys they will become avaible to aplication after that delay in a burst (normal delay between them). If I quit the application and restart the delay becomes 0 (or almost) again. The problem as I see it is: "I press a key - the delay increases". Any ideas or ways to reset some kind of internal key buffer are welcome.
-----------------------------How to create atmosphere? Bring in EMOTIONS!
Advertisement
Are you doing anything overly complicated in keyPressed()?, because that method should exit as fast as possible. If you are not doing this already, try just setting/resetting flags in the keyPressed()/keyReleased() methods and handling the logic in the main game loop.

Another factor that could affect this is if your game loop is too "tight", ie, not enough sleep time between runs. This will not free up enough processor time for the UI thread to handle the key input (especially if you're using serviceRepaints() or flushGraphics() since they would move paint requests to the top of the queue and they would be handled before key input).

shmoove
Thx to your advice I fixed the problem.

The game mechanics were updated on paint() and the run() method only had a short loop with a serviceRepaint() call somewhere. I removed that and I also put thread to sleep for 10 milliseconds.
-----------------------------How to create atmosphere? Bring in EMOTIONS!
If you haven't done so, I'd suggest moving the logic out of paint() and putting it in run(). paint() can get called when you don't expect it sometimes (like after a low battery or incoming message alert), and that can mess things up a bit. Also it's a method called by the UI thread so it should be as fast as possible.

shmoove

[Edited by - shmoove on July 27, 2005 7:35:51 AM]
with the Kyocera K10, it is not uncommon for it to recieve keypressed()/keyreleased() up to 500 milliseconds after they key is pressed, espeicially during continuous gameplay. Personally I just think the phone is junk.

~guyaton
~guyaton
Unfortunatly the code have been written by someone else. I always use the run/paint Java game structure (as every game for every platform should have).

At this moment the game has gone gold already and there is nothing to do - it runs just fine :)

@Kyocera K10 - I don't know this phone. From what you describe I suppose it is not a game platform with all efforts.
-----------------------------How to create atmosphere? Bring in EMOTIONS!
Oh well. Just don't forget to slap the person who wrote the code [wink]

All's well that ends well I guess.

shmoove

This topic is closed to new replies.

Advertisement