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

2018/8/24

Different actions when holding down a button

Recorsi Recorsi

2018/8/24

#
Hello, is it possible to track how long a putton is pressed (like a charge) and if so, how? thanks
Asenoju Asenoju

2018/8/24

#
You could define a new variable which counts how long you press a button by adding +1 every act-step the button is pressed. Like so:
int count;

...
public void act()
{
       if(Greenfoot.isKeyDown(YourKey)){
             count++;
       }
       if(count == yourDesiredAmount){
             doAction();
             count = 0; //This is important, you have to reset the count variable somewhere!   
       }
}
You need to login to post a reply.