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
// doctest-ignore
// gameTime is supplied by MonoGame's Update(GameTime) override.
_position = PhysicsIntegration.Euler(_position, _velocity, gameTime.ElapsedAsDuration());
Remarks
Eliminates the boilerplate Duration.FromSeconds(gameTime.ElapsedGameTime.TotalSeconds)
at every physics or movement update call site.