XNA GameTime before first Update
Someone asked on Game Development:
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?
I posted the following answer, which was chosen as the accepted answer and received 5 upvotes:
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.
Notable comments
Nate (0 upvotes): Yes, that is likely, but it still doesn’t remove having a line in the Update method which passes gameTime somewhere else.
Originally posted on Game Development — 5 upvotes (accepted answer). Licensed under CC BY-SA.