We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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!
Answers
I'm a beginner at java and processing so what I really want to know is whether or not my method will work.
Well...
you don't show your full code.
Remember that draw() runs 60 times per second approx.
All that happens is sumed up into an internal canvas and when draw() is done the screen is updated.
All movements that are shown while draw() can not been seen since draw() updates the screen only at its end
Therefore a for-loop can't do the job.
I suggest that you look into the examples for animation
hint: use the looping of draw() itself in saying
;-)
here
I suggest that you look into the examples for animation
there are also examples with gravity - you'll have to remove the bouncing to other spheres, but gravity is there:
https://processing.org/examples/bouncybubbles.html
I think those are better than my sketch
;-)