+ Reply to Thread
Results 1 to 4 of 4

Thread: Buffer of excess key presses in Java

  1. #1
    is on the 1st circle: Limbo
    Join Date
    Jun 2009
    Location
    US
    Posts
    1

    Default Buffer of excess key presses in Java

    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

  2. #2
    is on the 2nd circle: Lust
    Join Date
    Apr 2009
    Posts
    80

    Default

    please clarify i don't understand!....
    ]

  3. #3
    Super Moderator Richard_Rahl's Avatar
    Join Date
    Mar 2007
    Location
    Right behind you!
    Posts
    2,044

    Default

    Quote Originally Posted by jaypaul View Post
    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.
    Last edited by Richard_Rahl; 06-08-2009 at 06:13 PM.
    >>>>> Why should you use OGG for your media? (external link)
    My blog "The Force of Open Source" (external link)

    If you want to accomplish something in the world, idealism is not enough. You need to choose a method that works to achieve the goal. - Richard Stallman


  4. #4
    is on the 2nd circle: Lust
    Join Date
    Feb 2009
    Posts
    160

    Default

    Quote Originally Posted by daragez View Post
    please clarify i don't understand!....
    hahaha!!! now you know...
    trinity

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts