PDA

View Full Version : Buffer of excess key presses in Java



jaypaul
06-08-2009, 09:01 AM
Hi Friends,

Right now, in the game I am working on, if the user presses a key multiple times the actions

will be performed as many times as it registers, even though I disallow key presses during the time that the action is taking place.

For example, a move of 1 space can be carried out with a key press. While the character is moving, key presses are not allowed. However, if you just press the key 5 or 25 times, the

character will just keep moving, once he's done with the first one.

What I need to do is clear the buffer of key presses after an action has taken place, so that the excess keys are not registered. I know the commands to do so in C++, but not in Java.

Your Answers'll be Helpful.

Thanks
Paul

daragez
06-08-2009, 11:26 AM
please clarify i don't understand!....

Chevalr1c
06-08-2009, 05:10 PM
Hi Friends,

Right now, in the game I am working on, if the user presses a key multiple times the actions

will be performed as many times as it registers, even though I disallow key presses during the time that the action is taking place.

For example, a move of 1 space can be carried out with a key press. While the character is moving, key presses are not allowed. However, if you just press the key 5 or 25 times, the

character will just keep moving, once he's done with the first one.

What I need to do is clear the buffer of key presses after an action has taken place, so that the excess keys are not registered. I know the commands to do so in C++, but not in Java.

Your Answers'll be Helpful.

Thanks
Paul
Well, the only experience I have with such situations is a matter of Gamemaker 4. So I don't know the right Java algorithm, but the principle (thus not the real code) is something like this:


While key_arrow_right_press then x += 3 else _____//3 should be replaced by the right amount of pixels per "step" of the character//

x = current AND y = current ________//note that I don't know a better way of expressing a "stop" or "stay"//

So I think you should use a while-loop somehow. When the key is released or unpressed, the event ends. Do you get my meaning?

Oh, and sorry for not being able to give you the real java code, my programming skills are not getting further than a bit of Gamemaker 4 and some basic skills in Pascal and Delphi (but the latter is a few years ago so I think I've forgotten most of that).

@Daragez: it is a topic on (game) programming. :)

denice25
06-09-2009, 04:08 PM
please clarify i don't understand!....

hahaha!!! now you know...:lol: