Game.TargetElapsedTime Property

Gets or sets the target time between calls to Update when IsFixedTimeStep is true.

Namespace: Microsoft.Xna.Framework
Assembly: Microsoft.Xna.Framework.Game (in microsoft.xna.framework.game.dll)

Syntax

public TimeSpan TargetElapsedTime { get; set; }

Property Value

The target time period for the game loop.

Exceptions

Exception type Condition
ArgumentOutOfRangeException The value specified for TargetElapsedTime is not greater than zero. Specify a nonzero positive value.

Remarks

When the game framerate is less than TargetElapsedTime, IsRunningSlowly will return true.

The default value for TargetElapsedTime is 1/60th of a second.

A fixed-step Game tries to call its Update method on the fixed interval specified in TargetElapsedTime. Setting Game.IsFixedTimeStep to true causes a Game to use a fixed-step game loop. A new XNA project uses a fixed-step game loop with a default TargetElapsedTime of 1/60th of a second.

In a fixed-step game loop, Game calls Update once the TargetElapsedTime has elapsed. After Update is called, if it is not time to call Update again, Game calls Draw. After Draw is called, if it is not time to call Update again, Game idles until it is time to call Update.

If Update takes too long to process, Game sets IsRunningSlowly to true and calls Update again, without calling Draw in between. When an update runs longer than the TargetElapsedTime, Game responds by calling Update extra times and dropping the frames associated with those updates to catch up. This ensures that Update will have been called the expected number of times when the game loop catches up from a slowdown. You can check the value of IsRunningSlowly in your Update if you want to detect dropped frames and shorten your Update processing to compensate. You can reset the elapsed times by calling ResetElapsedTime.

When your game pauses in the debugger, Game will not make extra calls to Update when the game resumes.

See Also

Tasks

Achieving Good Performance on Different Hardware Types

Reference

GameTime.IsRunningSlowly Property
Game Class
Game Members
Microsoft.Xna.Framework Namespace

Platforms

Xbox 360, Windows 7, Windows Vista, Windows XP