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

2013/5/27

typing game

Rudi Rudi

2013/5/27

#
is there someone can help me about making game like typing game??? I'm confused in keyboard input...
There are two ways to get keyboard input. There is:
  • isKeyDown(String key)
  • getKey()
The isKeyDown(String key) will return true or false if a specific key is pressed at the moment that method is called. For the arrow keys, the key is "up", "down", "left", and "right". Almost everything else is how it is on the keyboard. (For more details, go to Greenfoot from here: http://www.greenfoot.org/files/javadoc/) The getKey() method may be harder to use for some people (it is for me). It will either return a string of the last key pressed, or null if nothing was pressed since the last time getKey() was called. If you want to use either of these to cause an action to happen, you will have to implement it like below:
//isKeyDown()
if (Greenfoot.isKeyDown(/*The Key*/)
{
    doSomething();
}

...

//getKey()
String key = getKey();
if (key != null && key.equals(/*The Key*/) //The order of that statement is very important!
{
    doSomething();
}
I hoped that helped!
Rudi Rudi

2013/5/27

#
ok, thanks, i'll try it!!!
Rudi Rudi

2013/5/28

#
may u have the example of scenario from the typing game???
You need to login to post a reply.