Game Input Timing

Started by
0 comments, last by Zenroth 24 years, 6 months ago
Ok i have recently run into a bit of a problem ive tried a few things to fix the problem,and they didnt work well. So here i am.

Ok i am using directinput for checking keys in my logic loop. Basicly

Keyboard->GetDeviceState( sizeof(diks), &diks );

int KEY(int key){
return diks[key] & 0x80;}

if (KEY(DIK_ESCAPE)) PostMessage(hwnd, WM_DESTROY,0,0);

Ok this works great so far. Now i come to my problem

if (KEY(DIK_UP) && KEY(DIK_LEFT))player1.y-=1, player1.x-=1, player1.dir = DIR_NORTH_WEST;

Ill tell you a bit more bout what im trying to do so that the above might make a little bit more sence. Im using 8-way graphics and i have bitmaps for each direction. The problem is i can never get the diagonal to work. I mean they work if i hold them down but i can't ever get the direction to stay as a diagonal. I guess it sees that one of the direction keys was down for a millisecond longer than the other so it goes up or left ect. So what i need i think is some type of a delay. Sleep(1) works perfectly but kills my framerate very badly.

Any Thoughts on how to get this working?

Advertisement
you should never use sleep() in a game.
just use timeGetTime() and set a delay on the input if they just hit a diagonal, or something similar to this.

This topic is closed to new replies.

Advertisement