Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing a game using fixed time step, and so far I haven't been using XNA's GameTime class in my code. What uses does the class have, and should I definitely use it in my game, or can I ignore it?

share|improve this question
up vote 0 down vote accepted

You can ignore it if you want. Just be aware that XNA on Xbox and PC defaults to a fixed time-step of 60FPS, but Windows Phone defaults to 30FPS. By using GameTime.ElapsedTime you can ignore this difference.

It can also make your code clearer if you work in seconds or milliseconds (but please not both!). For example you might be specifying that an action lasts "30 frames", but it might be clearer to specify it as "0.5 seconds".

Just be aware that only Update runs a fixed number of times per second. Draw might get called a lot less frequently.

If you ever disable the fixed frame rate, then using GameTime.ElapsedTime is critical.

One very good reason you might want to disable it - at least during development - is for profiling. Possibly using a profiler (like the guy in this recent question) so that profiling time isn't spent waiting for the next frame. But also just to do simple frame-rate comparison profiling: maybe you get 100FPS normally and make some change - you get 90FPS afterwards, so it was a bad change. This is not possible if your frame rate is capped at 60FPS.

share|improve this answer
Would it be a good idea to make the GameTime instance globally available through a GameServicesContainer? I'd like to be able to access it when I need it without passing it as an argument all the time. – Celarix Feb 19 '13 at 22:17
@Celarix That is certainly an easy thing to do, and not unreasonable. It is bad engineering - a bit of a hack - but that can be ok if it helps you make your game faster. It becomes a problem if you decide you want to do "interesting" things with your game objects later on (eg: run them at different rates for time-based effects, run them on separate threads, make neat graphing tools, etc). But then it is also very easy to undo that hack later on - "Find All References" is your friend, in that case. – Andrew Russell Feb 22 '13 at 11:57
I'll definitely take that under consideration. Thanks! – Celarix Feb 22 '13 at 20:48

XNA (in fixed time mode) will try to call you 60 times per second, but that doesn't mean that the calls are always 1/60th of a second apart. GameTime will tell you how much time has elapsed since the last call, and you should use that to feed into any time-sensitive calculations.

share|improve this answer
Usually the elapsed time is used to ensure that animations or other time-based events always perform at the same speed regardless of how often the update or draw calls are made. To use it you would either accumulate the elapsed time over successive Update calls and then use that value to determine how far along the time-sensitive task you are, or you can use it incrementally to determine what percentage of a time-sensitive task occurred between the last update and this one. – RobCurr Feb 17 '13 at 20:10

Your Answer


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.