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

2017/12/7

How do you make an object jump when the space bar is pressed?

ThorneC ThorneC

2017/12/7

#
I am new to Greenfoot, so don't know much about it. If you could make your answers as simple as possible I will appreciate it.
danpost danpost

2017/12/7

#
ThorneC wrote...
I am new to Greenfoot, so don't know much about it. If you could make your answers as simple as possible I will appreciate it.
This is really too general of a question with no given code to work off of (or with). The best general answer I can come up with is, using pseudo-code, something as follows:
if (<< on ground >> && << space key down >>) << set field for vertical speed to some negative value >>;
where vertical movement is done with a line of code similar to the following:
setLocation(getX(), getY()+<< vertical speed >>);
You need to login to post a reply.