Share via


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

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. Using a fixed step allows game logic to use the update as its basic unit of time and assume that Update will be called at the interval specified. When an update runs slower than expected, Game meets this assumption 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 slow down.

When using a fixed-step game loop, rates such as the distance a sprite moves can be expressed as game units per Update. This enables you to simply increment the position of the sprite by the sprite's movement rate each Update.

See Also

Concepts

Application Model Overview

Reference

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

Platforms

Xbox 360, Windows XP SP2, Windows Vista