hi! I made one game with loop.And there is game screen in the end.But this screen should be active for 5 seconds in the loop.My code is like this:
void draw()
{
...
if( frameCount / 60 == 3 )
{
fill(255, 0, 255);
textSize(100);
text("GAME OVER!", 80, 500);
playGame = false;
if( playGame == false && frameCount > 180 )//wait 5 seconds
{
playGame = true;
}
....
there is something wrong but i don’t know why this code isn’t working.Can you help me please?
1 Like
Chrisir
2
separate where you set playGame and where you display the message
boolean playGame=true;
int gameTimer=0, gameOverTimer=0;
// in draw()
// step 1: set game over?
if (playGame) {
if (millis() - gameTimer > 30000) { // 30 seconds
playGame = false;
gameOverTimer = millis();
}
}
// step 2: display message
if (playGame == false) {
fill(255, 0, 255);
textSize(100);
text("GAME OVER!", 80, 500);
if (millis() - gameOverTimer > 5000) {
// wait 5 seconds
// go back:
playGame = true;
gameTimer = millis();
}
}
glv
3
Hello,
Try it with two separate if()
blocks.
Use println()
statements to monitor flow of code.
void draw()
{
if( )
{
//...
println("Game Over!");
println(playGame);
}
if( )//wait 5 seconds
{
//...
println(playGame);
noLoop();
}
}
:)
thank you!!! I will try to add it to the game
1 Like