The TimeManager provides functionality for measuring differences in time. The TimeManager can be used to tell how much time has passed since an event has occurred, how much time is left before a predetermined event will occur, how much time the last frame took to process and render, and to profile code performance.

Retrieving Frame Length

For information on how long a frame has taken, see the SecondDifference page.

Absolute Time

The TimeManager.CurrentTime returns the number of seconds that the application has been running for. This value can be used to find the amount of time that has passed since an event has occurred, or mark the time for when an event should occur.

The following code shows how to check how long it has been since an Entity has been created and then makes the CircleInstance within the entity invisible after five seconds.

TimeManager and GameTime

XNA provides a GameTime reference in the Game’s Update and Draw methods, so question of which to use may arise – GameTime or the TimeManager? The TimeManager’s CurrentTime is equal to the Game’s TotalGameTime.TotalSeconds property so in Update they can be used interchangeably. Since the TimeManager is always in scope it is recommended for consistency to use this instead of passing references to the GameTime.



Did this article leave any questions unanswered? Post any question in our forums for a rapid response.