How to detect if key is pressed once or is being held down?

  • Thread starter Thread starter Gameatro
  • Start date Start date
G

Gameatro

Guest
I am making a platform game in direct2d. I am having a problem with jump. I made a logic that if the "w" key is pressed a negative speed is given to the character, so it goes up some distance and comes down. My problem is that if the "w"key is held down my character goes flying up. I want the jump to happen only once. I tried this:-
if((GetAsyncKeyState('W')&(0x1)==(0x1))
....do jump
but in this case my character jumps, come down a bit and they goes flying up if w is held. I found another way that I check if my character is on ground before jumping which is working. But I also want to detect whether "D" and "S" are held down so I can run the walking animation and then return to standing when key is released. is there any way do so? pls help me

Continue reading...
 
Back
Top