We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I need a countdown timer for a game.. It should pause when the key dedicated for pause is pressed and it should continue when its unpaused. The timer should display on the screen. I have tried many ways but none of them work. Below is the code for my keypressed. It would be great if someone could help me with it.
Below is my keypressed code: final int k = keyCode;
void keyPressed () {
if (k == 'P')
if (looping) {
text("Game Paused",200,200);
noLoop();
}
else {
loop();
}
}
Answers
I am on a journey
I look monday
;-)
For a countdown you mean in seconds ?
And counting from where down to zero? From 50 seconds?
What happens at zero?
;-)
this one is not really precise...
it needs to be a countdown timer from 60 seconds. when it reaches 0 the game ends
Thank you.
Function millis() isn't affected by noLoop(). Merely the auto callback to draw() is turned off.
So, rather than base the timer on millis(), we can use the current value of frameCount:
http://processing.org/reference/frameCount.html
Every time draw() is invoked, frameCount is automatically increased by 1.
By default, frameRate() is 60 FPS. Therefore, 1 second means 60 frameCount! :-B
In order to have a countdown of 1 minute, we're gonna need an elapsed
TIMING = FPS * 60
! *-:)Take a look at how it works online: (*)
http://studio.processingtogether.com/sp/pad/export/ro.9Djm2xo4wna7I/latest
And here's the source now: o->