Class GameTimeExtensions
Extension methods for Microsoft.Xna.Framework.GameTime that bridge MonoGame's time model to UnitsNet's UnitsNet.Duration type.
public static class GameTimeExtensions
- Inheritance
-
GameTimeExtensions
- Inherited Members
Methods
ElapsedAsDuration(GameTime)
Returns the elapsed game time as a UnitsNet UnitsNet.Duration.
public static Duration ElapsedAsDuration(this GameTime gameTime)
Parameters
gameTimeGameTimeThe current game time provided by MonoGame's
Updatemethod.
Returns
- Duration
A UnitsNet.Duration equal to
gameTime.ElapsedGameTime.TotalSeconds. Sub-millisecond precision is preserved because TotalSeconds returns a double.
Examples
var gameTime = new GameTime(TimeSpan.Zero, TimeSpan.FromMilliseconds(16));
Duration dt = gameTime.ElapsedAsDuration();
Remarks
Eliminates the boilerplate Duration.FromSeconds(gameTime.ElapsedGameTime.TotalSeconds)
at every physics or movement update call site.