try to think as in real life, you have gravity. so every loop, you must have something moving your sprite down, unless its touching ground. suppose ground is 0. your sprite is at zero and cannot go underground. now, if it were to somehow leave 0(ground) there must be gravity, something that subtracts height every loop. now lets say gravity is 5. so, when your player jumps, you add some value to your vertical velocity, lets say 20, before adding this, it was 0, you had no velocity upwards or downwards. now, by adding velocityy we take off the ground, so now we are at 20, not at zero, but since there is gravity, you have to subtract it from your velocity, so your final position is 15. so then you advance 15 but - 5 of gravity, is 10, you are now at height 25, then your velocity decreases to 10, you now are at 35 then velocity decreases to 5, and you reach your max height, which will be 40. after that, your velocity becomes negative, which makes your sprite fall down until it reaches zero. some pseudocode example:
darkgdkloop
{
if(buttonpressed)
{
vx=20;
}
positionY=spriteposition;//we must know where it is
if(positionY>0){playerisonground=false}
else{playerisonground=true;}
if(playerisonground==false)//player not on ground, so we must have gravity
{
vy=vy-gravity;//where gravity can be any value. lets say you assigned 5
}
positionsprite(xposition,positionY+vy);
}
try it. i know it will work
hi