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.
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.
// We'll store the value outside of any functions
// so we can set it in CustomInitialize but check against
// it in CustomActivity
private void CustomInitialize()
// Store off the time...
timeInitialized = TimeManager.CurrentTime;
private void CustomActivity()
// Check if more than 5 seconds have passed. If so...
if(TimeManager.CurrentTime - timeInitialized > 5.0)
// ... make the circle invisible
this.CircleInstance.Visible = false;
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.
- FlatRedBall.TimeManager:Accumulating Time
- FlatRedBall.TimeManager:Working with TimeSpan
Did this article leave any questions unanswered? Post any question in our forums for a rapid response.