DInput: Up is fine, left is fine, but Up+Left is one or the other?

Started by
5 comments, last by xegoth 19 years, 8 months ago
Howdy I'm sure this is a common thing, but I've done some searches and can't find an answer. I'm using DirectInput for keyboard input for a game but I have a problem. If I press up, the character jumps. Fine, no probs. If I press left, the character moves left. Couldn't be better. However, if I press up and left, hoping for a jump to the left, it doesn't always happen. Sometime it does if you time it right, but most of the time you get either up or left. So my question is, how do you handle input that allow for combinations to work aswell as individual keys. I tried putting a delay in between keyboard reading, but then the character is slow to respond which is annoying. Any help would be greatly appreciated. I may even name my first born after you. Rob.
Advertisement
How are you doing input, buffered or unbuffered? If you are doing buffered, you may need to set the Buffer size higher so it can hold more than one entry...
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
Actually, I'm using unbuffered. Is that the prob?

Thanks.

Rob.
Actually that shouldn't be a problem for unbuffered.

How are you checking the pressed keys? Don't use an "else if" if you want the game to react to both keys at the same time.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Does this give any meaning on the problem you're having, or is it something else in your case?

-Mezz
They are two possibilities ...

- First is to use

// If both Up and Left Keys are down, then
if ((KeyBoard.KeyDown (DIK_UP)) && ((KeyBoard.KeyDown (DIK_LEFT))
{
// do your stuff
}

- Other is calculating when making transformation. When Up Key is pressed the player jumps at certain height (store height value). When left key is pressed the player moves in the left direction (store left direction value). Just calculate (both left and height) things before you set up transformation.

Ofcourse this all depends upon your game requirements. If you want your player to control his movement during jump then I would rather prefer going for the second one.

I hope I was clear.
I've done a lot of stuff with directinput and chances are you're using else if for your key reading code.

// If both Up and Left Keys are down, then
if (KeyBoard.KeyDown (DIK_UP))
{
// do your stuff
}
else if(KeyBoard.KeyDown (DIK_LEFT))
{
//
}

That would mean if you pressed up and left it'd move up. Get rid of the else and it should move diagonally. That's the most simple/likely answer.

This topic is closed to new replies.

Advertisement