TimeSpan

v4.0

The TimeSpan class contains float values for in-game seconds, minutes, hours, days, weeks, months, seasons, and years. This is used in a variety of the GameTime methods, and can also be saved to isolate specific chunks of time that are important to your project.

Many methods which utilize this concept will allow both a TimeSpan object, or a list of floats designating the specific TimeSpan to utilize.

public float Seconds
public float Minutes
public float Hours
public float Days
public float Months
public float Years

TimeSpan does not track time itself, and does not decrease as time passes.

Create a TimeSpan

// Create a new Timespan object for 2 weeks -- Each value is optional, defaults to 0
TimeSpan myTimeSpan = new TimeSpan
{
    Weeks = 2
};

// Create an empty Timespan, then populate it
TimeSpan respawnTime = new TimeSpan();
respawnTime.Years = 1;
respawnTime.Months = 6;

Methods

Add another TimeSpan

Multiply by a multiplier float value

Remember that all values in a TimeSpan are based on in-game time.

Timespan Methods on Gametime.cs

These general methods will return a TimeSpan object, which may be saved and used later.

Convert from TimeSpan

See all the conversion methods on the Gametime Properties & Methods page

Last updated

Was this helpful?