creating a delay after a collision

edited November 2017 in How To...

Hey, I'm trying to create a delay in-between when a collision occurs and when I have my game over screen to pop up. I want the program to still be running but have a five second delay before game over shows up. I've tried a few methods such as using millis() but it always starts right when I start my program. Could someone tell me how I should go about this? thanks in advance.

Tagged:

Answers

  • edited December 2017 Answer ✓
    boolean doom_timer_active;
    int doom_timer;
    
    if( collision ){
      if(!doom_timer_active){
        doom_timer = millis() + 5000;
        doom_timer_active = true;
      }
    }
    if( doom_timer_active && millis() > doom_timer ){
      game_over();
    }
    
  • I love you

  • Don't applaud, just throw money (via PayPal) (to tfguy44@gmail.com).

Sign In or Register to comment.