[java] Input without delay
Hello,
I'' ve only started programming Java today so this mught be a really stupid question but I can''t find an answer. My problem is that when I press akey when running my applet it has the desired effect but it then pauses before continuing normally ie there is a delay in getting the next "key flag". I guess I''ve explained that really badly so I''ll try again:
I have an applet that moves a bitmap with the arrow keys but there is a delay if I hold down one of the arrow keys, just like the delay in a text editor when you hold down a key. This really messes up everything because it''s very annoying. So I how can I fix that problem, I would really appreciate any help thanks.
Sounds like your program is only acting on key typed events not key pressed events. I seem to recall that some key events only generate id numbers for typed events.
I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!
I wanrned you! Didn't I warn you?! That colored chalk was forged by Lucifer himself!
"... we should have such an empire for liberty as she has never surveyed since the creation ..."Thomas Jefferson
I usually make a boolean flag, say up_flag
when keyPressed is the up key set up_flag to true
when keyReleased is the up key set up_flag to false
in the main loop before you do the drawing check what is pressed and move the objects accordingly. You do it this way to make the movement smooth, instead of like when you hold down a key on the keyboard in a text editor
when keyPressed is the up key set up_flag to true
when keyReleased is the up key set up_flag to false
in the main loop before you do the drawing check what is pressed and move the objects accordingly. You do it this way to make the movement smooth, instead of like when you hold down a key on the keyboard in a text editor
author of the Helping Phriendly Book
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement