Is there a conventional way to get key input?
I'm having a little problem with my key input, I need a delay before the game registers the key again so my tetris blocks doesn't spin themselves dizzy. I've tried with brute force but that only resulted in the game also skipping key presses when I didn't want it to.
I'm going to experiment a bit but my thought was is there a conventional way to do it?
Quote:Original post by Chris OdenWhat API are using for keyboard input?
I'm having a little problem with my key input, I need a delay before the game registers the key again so my tetris blocks doesn't spin themselves dizzy. I've tried with brute force but that only resulted in the game also skipping key presses when I didn't want it to.
I'm going to experiment a bit but my thought was is there a conventional way to do it?
Depending on what API you are using, it might be possible and desirable to watch for other key state transitions. For example, in Win32 you could watch for the WM_KEYDOWN/WM_KEYUP messages, which are sent only when the key moves from one state to the other. This would allow a block to spin as fast as the button could be pressed, but would not spin wildly when held down.
Another way is to timestamp each keypress on a per-key basis. Then, if not enough time has elapsed, you simply reject each additional keypress. When enough time has elapsed between keypresses, you accept that keypress, update the timestamp to reflect the accepted keypress, and process that input as usual. This method gives a great deal of flexibility in how you can define the input to behave as well as being independent of game cycles.
Another way is to timestamp each keypress on a per-key basis. Then, if not enough time has elapsed, you simply reject each additional keypress. When enough time has elapsed between keypresses, you accept that keypress, update the timestamp to reflect the accepted keypress, and process that input as usual. This method gives a great deal of flexibility in how you can define the input to behave as well as being independent of game cycles.
Heh, just fix it!
I kid.
I'm using SDL in a win32 API, and as it is now I poll events in the main loop and then check what that event is in every class that needs it.
It only runs the movement if the event == SDL_KEYDOWN, I though it would make it run only once when the key was pressed but it runs continually.
I kid.
I'm using SDL in a win32 API, and as it is now I poll events in the main loop and then check what that event is in every class that needs it.
It only runs the movement if the event == SDL_KEYDOWN, I though it would make it run only once when the key was pressed but it runs continually.
Quote:Original post by Chris OdenSDL has functions for enabling or disabling key repeats and for adjusting the parameters (delay and time interval) thereof.
I'm using SDL in a win32 API, and as it is now I poll events in the main loop and then check what that event is in every class that needs it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement