How to make a timer in Processing?

So I know this is a really simple question, but I can’t figure out how to do it!

So I have this code:

void draw()
{
    if (startGame)
        // do stuff

   if (lose)
       DisplayTimer();
}

void mousePressed()
{
    startGame = true;
}

So as soon as the person pressed the mouse, it starts the timer. And when the person loses the game, the timer stops. Now I considered using millis() however I can’t figure out how it make it start when the game starts.

Can anyone help me? Thanks

1 Like

millis() started counting as soon as you started your sketch.

An example here:

:)

2 Likes