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'm wanting to add a timer in an XNA game using C#. The ultimate goal is to increment a score in a game every second by 10 points. As of now the score stays at zero. Watching YouTube videos is proving to be counter productive as they're quite confusing.

Thanks.

share|improve this question
2  
Show code of what you have tried up to now. –  Jon May 3 '13 at 14:41

1 Answer 1

I believe something like this should work. (Place the code in the Update block)

Timer += gameTime.ElapsedGameTime.TotalMilliseconds; // Increment the timer by the elapsed game time.

if (Timer >= 1000) // Check to see if one second has passed.
{
    Points += 10; // Increment the points by 10.
    Timer -= 1000; // Reset the timer.
}
share|improve this answer
    
Note that Timer is a number, not an instance of special class. –  John McDonald May 3 '13 at 19:03

Your Answer

 
discard

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