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

2014/3/12

Asign Key Up?

Pointifix Pointifix

2014/3/12

#
Is there anything with which i can check if lets say "space" key goes up, so not to check wether its down, i just want to get one input, not many as in Greenfoot.isKeyDown();
danpost danpost

2014/3/12

#
Use the Greenfoot method 'getKey', assign the returned value to a String variable. Compare the value of the variable to expected key using, for example:
1
2
String key = Greenfoot.getKey();
if ("space".equals(key)) { /** etc */
Never compare in the opposite order -- like 'key.equals("space")' -- unless you check to make sure that 'key != null' first or that ol' NullPointerException will show its face.
Pointifix Pointifix

2014/3/12

#
ok you´ll need an extra string, thanks
Pointifix Pointifix

2014/3/12

#
another question, how can i make one pixel transparent?
danpost danpost

2014/3/12

#
Pointifix wrote...
ok you´ll need an extra string, thanks
If you only have to check for one key, you can use 'if ("space".equals(Greenfoot.getKey()))', otherwise you will need the string because once called the key is removed from the buffer and you cannot get it back again.
Pointifix wrote...
another question, how can i make one pixel transparent?
Use the GreenfootImage method 'setColorAt'. I normally use 'new java.awt.Color(0, 0, 0, 0)' for transparent.
Pointifix Pointifix

2014/3/12

#
r, g, b, and alpha ? k thanks
You need to login to post a reply.