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.

Using XNA, is it possible to access the GameTime object before Update is called for the first time?

Can it be used in the game constructor, Initialize or LoadContent methods?

share|improve this question
4  
Wouldn't you just assume its value is zero anyway? –  Andrew Russell Apr 18 '11 at 14:38
2  
I'm curious as to what is your purpose there, if you wish to share. –  jv42 Apr 18 '11 at 14:52
    
I need to pass it to another static class that manages game time as well as other time related things that are specific to the project. At the moment the first opportunity I have to do this is on the first Update loop, every loop after that the line is redundant. I was wondering if there was a cleaner way to do it. –  Jaxe Apr 18 '11 at 16:27
    
It's not that big of a deal... It's certainly not going to cause massive frame loss or anything. –  Michael Coleman Apr 18 '11 at 17:44
1  
I realise that, but it's not very elegant. –  Jaxe Apr 18 '11 at 17:49
add comment

1 Answer 1

up vote 5 down vote accepted

I don't believe this is possible:

The GameTime object received by Draw and Update isn't technically owned by anyone, but is instead re-created each Game.Tick and passed to Update and Draw from there.

Internally, Tick fills the value of the Total/ElapsedRealTime properties based off of the current high performance counter value as reported by Stopwatch.GetTimestamp(). If the PC the program is running on does not have a high performance counter, then it returns DateTime.Now.Ticks.

The Game Time properties (as opposed to real-time) also use the Stopwatch.GetTimestamp, however elapsed time since application launch and last frame are computed internally and then filled in before GameTime is passed to Draw or Update - so there's no external way to compute those values directly.

Source: http://forums.create.msdn.com/forums/t/10587.aspx, bold mine. Also included there are several work arounds, similar to what you've already outlined though.

share|improve this answer
    
Based on this, the main game Update method could probably update the static time manager class mentioned before any subsequent game components needed it, ie before calling base.Update. –  DrDeth Apr 18 '11 at 19:01
    
Yes, that is likely, but it still doesn't remove having a line in the Update method which passes gameTime somewhere else. –  Nate Apr 18 '11 at 19:12
    
Thanks, I'll play around with these workarounds and see what works. –  Jaxe Apr 19 '11 at 13:59
add comment

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.