Sign in to follow this  
darcmagik

Slowing down input

Recommended Posts

darcmagik    255
Ok I'm working on a game right now and I'm creating a main menu system where I display buttons and when you press up or down on either the key board, or an XBOX360 controller that the selected button is changed. The problem I am having is that when you press the keys on the keyboard or the dpad on the controller it races through changing the selection so you see it highlight the different menu options very fast as it reads the inputs very quickly. I'm doing this in DirectX 9, using XInput for the controller and DirectInput for the keyboard any ideas for how to slow this down?

Share this post


Link to post
Share on other sites
Alatar    303
Do you have a timer of some kind? You could change the menu selection only if a certain amount of time has passed since the last time a key was pressed.

Share this post


Link to post
Share on other sites
Flimflam    665
In your input processing function, you should store two values. You need to store the collection of input from the current frame, and you need to keep the input from the previous frame.

When you're checking for input, you need to make sure that during the current frame, the button is pressed, and that during the last frame, the button is released. If both those conditions are true then you should increment the selected option on the screen.

Share this post


Link to post
Share on other sites
darcmagik    255
Well, maybe I'm doing my timing wrong, I'm working through a book on DirectX9 and in the book the author has us use if (GetTickCount() - start >= 30), start is set to GetTickCount() when the app starts running. I know there is a better way to do timing when it comes to this but I just don't know what it is?

Share this post


Link to post
Share on other sites
darcmagik    255
Also I am working on building a framework of my own for making games, and one of the things that I'm trying to figure out what to do is, should I put all DirectX related functionality, helper functions, etc... in 1 header and cpp file, or should I have a one set of files for graphics, one set of files for audio, one set of files for input, and a file for the windows related code, and another set of files for the actual game?

I'm trying to figure out the best way to organize things so that it works best.

Share this post


Link to post
Share on other sites
ender_341    136
are you making sure to reset start?

you should really use
DWORD newtime = GetTickCount();
if(newTime - start >= 30){
//////////////////////////
// Your handling code here
//////////////////////////

start = newTime;
}

Share this post


Link to post
Share on other sites
marius1930    119
For keyboard clicks you'll want to add a delay between repeated clicks.

Event: Key pressed
Case 1: Key is just pressed --> Change Selection
Case 2: Key is a REPEAT:
Case 2.1: Delta < Threshold --> Add to delta
Case 2.2: Delta >= Threshold --> set Delta=0, Change Selection



For the xbox controller however, i assume its behaving more like a mouse\mousewheel?
In which case you will have to check the distance traveled.

Event: moved controller
Case 1: Delta < threshold --> Add delta to threshold
Case 2: Delta >= threshold --> Set delta to 0, Change selection

My assumption about the xbox controller could be wrong, in which case you probably handle it as a keyboard event.

Share this post


Link to post
Share on other sites
themadme    122
Excuse me for not understanding this but to stop from cursor moving up and down fast is a simple solution.

All you need to do is have an if statement and boolean, example:

//global variable;
bool bPressed = false;

if(pInputMgr->getMouseKeyboard()->bKeyPressed(LEX::KEYS::_SPACE_) && !bPressed)
{
// do your code stuff here
bPressed = true;
}else if((pInputMgr->getMouseKeyboard()->bKeyReleased(LEX::KEYS::_SPACE_))
{
bPressed = false;
}

From above the cursor will only move if the user presses a button once, you coudl modify this to use a timer instead of a boolean

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this