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

2012/8/9

why can't i do this??

isaiah isaiah

2012/8/9

#
why can't i use the if("****".equals(Greenfoot.getKey())) twice. i have it on my jump() and on my shoot() i can jump but not shoot. if i use if(Greenfoot.isKeyDown("**")) on the arrow it makes a lot of arrows and i only want 1 arrow and if u use it on my jump then i jump really weird
Jinice Jinice

2012/8/9

#
Ya i would like to know this too please reply someone.
davmac davmac

2012/8/9

#
Because when you call Greenfoot.getKey() it tells you which key was last pressed, and then "forgets" that key. That way, you can tell if no key has been pressed since you last checked (it will return null). If you want to test multiple keys, use Greenfoot.isKeyDown(...), or save the return from Greenfoot.getKey() in a variable:
String key = Greenfoot.getKey();
if ("space".equals(key)) {

}
else if ("up".equals(key)) {

}
davmac davmac

2012/8/9

#
If you use Greenfoot.isKeyDown(...), you can use an instance variable to remember if the key was down last time (and not fire if it was) or to act as a timer for a delay between shots.
You need to login to post a reply.