Hello,
I have a problem with my code.
I want to set a timer which asks how long is a key pressed?
can you help me?
Here is my code:
public void pee() // Dude have to pee
{
Laden world=(Laden) getWorld(); //
if(Greenfoot.isKeyDown("p")) //if the key "p" is pressed
{
timer.mark(); // start Timer
if( Greenfoot.isKeyDown("p") && timer.millisElapsed()> 2000) // after 2 sec pressing "p", set new image, remove the object and beerscore -1
{
Blase7 blase7 = new Blase7();
world.addObject(blase7, 1132, 407);
blase7.setLocation(1125, 400);
getWorld().removeObject(this);
world.beerscore=world.beerscore-1;
}
}
}
