This site requires JavaScript, please enable it in your browser!
Greenfoot back
yuchoi
yuchoi wrote ...

2013/11/9

How do you make an actor jump?

yuchoi yuchoi

2013/11/9

#
I am making a simple game for my computer class and i've learned the basic commands including the counting method where you put "int count = 0" and "count = count + 1" and "if (count == 5)" and all that but what i want to know is how to make an actor rise up and make it come down after a while. my codes for my jump method is if (Greenfoot.isKeyDown("space")) { setLocation(getX(), getY() - 8); if (Greenfoot.isKeyDown("right")) { move(+2); } if (Greenfoot.isKeyDown("left")) { move(-2); } if (count == 4) { setLocation(getX(), getY() + 8); } } ------------------------------------------------------------------------------------------------------------ i know this is doing what it supposed to but i want the actor to stay up in the air for a visible while and come back down, and i can only use the codes i have learned. these two parts (the code below) are there because i want the actor to jump towards the direction i am moving if (Greenfoot.isKeyDown("right")) { move(+2); } if (Greenfoot.isKeyDown("left")) { move(-2); } thanks in advance :)
danpost danpost

2013/11/9

#
The horizontal movement, left and right, are independent of the vertical movement; meaning that jumping only deals with the vertical and has no effect on the horizontal; and the horizontal movement does not need any adjustment because of jumping. The code you provided above (if the counter begins incrementing upon a jump and is reset to zero after the jump) will cause your actor suddenly appear at a higher location for the duration of the count and then suddenly appear back at the lower location after the count. Your count limit of 4 is fairly small for what you have right now. A value more like 30 to 50 would probably give a more sufficient amount of time for the jump.
You need to login to post a reply.