Making a Sprite Jump using a for loop?

edited March 2015 in Questions about Code

Hi everyone,

I'm trying to make a sprite jump using a for loop that changes the y coordinate of said sprite 10 times, 5,4,3,2,1,0,-1,-2,-3,-4. Heres the code:

if(mousePressed == true && dist(mouseX, mouseY, 140, 880) < 30 && playerY > 0 && jumpCooldown == 0){

jumpCooldown = 1;

for(int i = 5; i > -5; i -= 1){

playerY = playerY - i;

}

}

The idea is that you can only jump one time at a time, if that makes sense. The sprite goes up then down. Unfortunately all this code does is make the sprite constantly go up, no downwards movement. Also is there a way to time the start and end of the if statement and the after a specific amount of time set the int jumpCooldown to 0 ?

Thanks in advance!

Tagged:

Answers

Sign In or Register to comment.