Advertisement

Input sensitivity for tetris clone

Started by April 06, 2002 12:00 AM
3 comments, last by alexdevmaster 22 years, 7 months ago
ok, i''ve built my first game, it''s a tetris clone, works wonderfully except for one thing, the input is too sensitive, that is to say when i press right or left arrow keys, the shapes move in those directions a bit too fast, and also rotate is moving too fast as well, my first solution was something like this int sensitive=0; while(1){ //main game loop sensitive++; if(key is pressed and sensitive > some value say 20){ do whatever sensitive=0; } }//end while which is attempting to lock the input to a particular frame rate but i dont like how that was workin so i tried to add a sleep in the condition, but that doesnt work too well either, in facts its worse, when i try to play the game on another computer, what i need is an efficient way to lock the input to a particular frame rate so that it will work the same on all computers, the game it self is locked to 33fps anybody with any suggestions "Jus chillin waiting for my time to shine" #define ALEX_DENNIS
"Jus chillin waiting for my time to shine"#define ALEX_DENNIS
I have the same problem in my clone. I have tried several different things and can''t get it smooth.

If you put a sleep condition in there you can miss input. That sucks and looks REAL bad. But left to its own devices, it samples at the full frame rate - also sucks. I am thinking of using flags in the main loop to represent the input and then checking the flags every few frames to actually move the peices. That way, I will get the delay and not miss any input.

I will let ya know if this works for me.

Good luck,
Landsknecht
My sig used to be, "God was my co-pilot but we crashed in the mountains and I had to eat him..."
But folks whinned and I had to change it.
Advertisement
why dont you use a timer?
One solution is using your sensitivity delay counter and flags. For example (in pseudocode):

if key press
keydelay++
if keypressed=false or keydelay>10
do movement
keydelay=0
end if
keypressed=true
else
keypressed=false
end if

This code will make the object move as soon as a key is pressed but will delay repeated moves when the key is held down.

You may also consider having a variable framerate to maximise usage of hardware capabilities.

Hope this helps,

Kev.
thanks alot, all your responses have been helpful, especially that last one from kevin, i''ll try it and then tell you how it turned out, if you dont see another post soon, then you know i got it to work :-) else i''ve just been busy, you know how it is when your a programmer, again thanks all

"Jus chillin waiting for my time to shine"
#define ALEX_DENNIS
"Jus chillin waiting for my time to shine"#define ALEX_DENNIS

This topic is closed to new replies.

Advertisement