Class GameExtensions
- Namespace
- Stride.CommunityToolkit.Games
- Assembly
- Stride.CommunityToolkit.dll
Provides extension methods for the IGame interface, enhancing game management and performance tuning functionality.
public static class GameExtensions
- Inheritance
-
GameExtensions
Remarks
These methods offer additional control over the game's timing, frame rate, and vertical synchronization, allowing for both performance optimization and flexibility.
Methods
DeltaTime(IGame)
Gets the time elapsed since the last game update in seconds as a single-precision floating-point number.
public static float DeltaTime(this IGame game)
Parameters
Returns
- float
The time elapsed since the last game update in seconds.
Exceptions
- ArgumentNullException
Thrown if the
game
is null.
DeltaTimeAccurate(IGame)
Gets the time elapsed since the last game update in seconds as a double-precision floating-point number.
public static double DeltaTimeAccurate(this IGame game)
Parameters
Returns
- double
The time elapsed since the last game update in seconds with double precision.
Exceptions
- ArgumentNullException
Thrown if the
game
is null.
DisableVSync(IGame)
Disables vertical synchronization (VSync) to allow for uncapped frame rates, potentially increasing performance at the cost of possible screen tearing.
public static void DisableVSync(this IGame game)
Parameters
EnableVSync(IGame)
Enables vertical synchronization (VSync) to prevent screen tearing by synchronizing the frame rate with the display's refresh rate.
public static void EnableVSync(this IGame game)
Parameters
Exit(IGame)
Exits the game if it inherits from GameBase; otherwise, throws an exception.
public static void Exit(this IGame game)
Parameters
game
IGameThe game to exit.
Exceptions
- ArgumentNullException
Thrown if the
game
is null.- ArgumentException
Thrown if the
game
does not inherit from GameBase.
FPS(IGame)
Retrieves the current frames per second (FPS) rate of the running game.
public static float FPS(this IGame game)
Parameters
Returns
- float
The current FPS rate of the game.
SetFocusLostFPS(IGame, int)
Sets the maximum frames per second (FPS) rate for the game when not in focus.
Set targetFPS
to 0 for uncapped FPS.
public static void SetFocusLostFPS(this IGame game, int targetFPS)
Parameters
game
IGameThe IGame instance on which to set the FPS limit.
targetFPS
intThe target FPS rate. Set to 0 for uncapped FPS.
SetMaxFPS(IGame, int)
Sets the maximum frames per second (FPS) rate for the game.
Set targetFPS
to 0 for uncapped FPS.
public static void SetMaxFPS(this IGame game, int targetFPS)