Hi guys I’m implementing jumping for my character in SDL 2 and I noticed that when I keep pressed the jump button (key S) the characters get stuck on the jump coordinate if I release it everything is fine (it gets down).
Please let me know how to fix it.
This is the important bit of my code for events I have the following:
//when key S is pressed:
case SDLK_s:
{
keys_Down = 1;
keys_Up = 0;
break;
}
//When Key S is released:
case SDLK_s:
{
keys_Up = 2;
keys_Down = 0;
break;
}
//In the movement function:
if(keys_Down == 1) //it means that I pressed S
{
Player.YPosition -= Player.JumpVelocity;
Player.Velocity = 0;
keys_Down = 0;
}
else if (keys_Up == 2) //it means that I released S
{
Player.YPosition += Player.JumpVelocity;
keys_Up = 0;
}