0
\$\begingroup\$

I am checking for key presses and then based on the keys pressed I am moving a square around the screen. I am setting booleans for the keys WASD. But , Whenever I try to keep the key down , it takes a while till it moves continuously (Just a half second stop after a single move.) Any way to get rid of that and make it be "smooth"? Code:

 up = false;
 down = false;
 left = false;
 right = false;
 reset = false;

 while(Keyboard.next()){
     if (Keyboard.getEventKeyState()) {
        if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)){
             reset = false;
        } 
         if(Keyboard.isKeyDown(Keyboard.KEY_W)){
            up = true;
        } 
        if(Keyboard.isKeyDown(Keyboard.KEY_S)){
            down = true;
         }
         if(Keyboard.isKeyDown(Keyboard.KEY_A)){
            left = true;
        }
        if(Keyboard.isKeyDown(Keyboard.KEY_D)){
            right = true;
        }
     }
}
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Since you're checking for events each update, you'll be relying on the key repeat events to start your continuous movement. That means that an event will be generated when the key is first pressed, then the repeat events will be created after a short delay.

So, try removing your check if (Keyboard.getEventKeyState()) and the while(Keyboard.next()) loop (that one is actually unnessary for how you're using the Keyboard class right now). That will allow the checks to operate without the event being triggered (thus bypassing the delay).

\$\endgroup\$
4
  • \$\begingroup\$ Nope , same thing. It is like the type delay(You hold a key down and after some time it starts giving repetitive signal) \$\endgroup\$
    – ntakouris
    Nov 4, 2013 at 19:58
  • 1
    \$\begingroup\$ Likely the Keyboard.Next() is also adding to this. It's not necessary for your current setup. \$\endgroup\$
    – House
    Nov 4, 2013 at 20:00
  • \$\begingroup\$ I cant believe I keep making that kind of mistakes again! Ah... thanks anyway! \$\endgroup\$
    – ntakouris
    Nov 4, 2013 at 20:05
  • \$\begingroup\$ No worries, have fun with it. Good luck! \$\endgroup\$
    – House
    Nov 4, 2013 at 20:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .