Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to make a countdown timer for my racing game such as "3... 2... 1... GO!" I'm using GLUT, OpenGL, and C++. I was wondering what the most appropriate method to handle this in C++. clock()? glutTimerFunc()? I plan on having 4 textured polygons that shrink and fade one after the other.

share|improve this question
2  
You could code your own time manager using glutGet(GLUT_ELAPSED_TIME); That way you have real frame time correlation with what the user should see on their screen. Some code here. That's probably easier since you don't have to worry about performing really OS specific time calls. –  teodron Apr 10 '12 at 17:35

1 Answer 1

up vote 1 down vote accepted

You need to accumulate time in your update loop. Don't think in terms of "what time it is", instead, keep a double variable, called timeTotal. Each frame, increment it by (1.0/60.0) (or whatever your fixed timestep is). When the game starts, you can reset the timer, and your race start introduction would just go something like this:

void update()
{
  totalTime += 1.0/60.0 ; //increase time

  if( timeTotal > 1 )  // 3.
  else if( timeTotal > 2 )  // 2.
  else if( timeTotal > 3 )  // 1
  else { GO } // race on

}

You can refactor this in any number of ways, but this is the basic idea of how to trip time based events in a game system.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.