A .NET library for hierarchical time management in games. Provides flexible clock objects that support pause, speed control, hit pause effects, and countdown timers.
$ dotnet add package GameTimerA .NET library for hierarchical time management in games. Provides flexible clock objects that support pause, speed control, hit pause effects, and countdown timers.
GameTimeusing GameTimer;
using Microsoft.Xna.Framework;
public class Game1 : Game
{
private GameClock _mainClock;
private GameClock _gameClock;
protected override void Initialize()
{
_mainClock = new GameClock();
_gameClock = new GameClock();
}
protected override void Update(GameTime gameTime)
{
// Update clock hierarchy
_mainClock.Update(gameTime);
_gameClock.Update(_mainClock);
// Pause gameplay (menu animations on _mainClock continue)
_gameClock.Paused = true;
// Slow motion
_gameClock.TimerSpeed = 0.5f;
}
}
| Class | Description |
|---|---|
GameClock | Base clock with pause and speed control |
CountdownTimer | Counts down from a duration with lerp support |
HitPauseClock | Freezes temporarily for impact effects |
TimeUpdater | Tracks time outside of XNA/MonoGame |
Clocks can update from other clocks, creating parent-child relationships:
MainClock (real time)
|
GameClock (pauseable)
/ | \
Player Particles Enemy
mainClock.Update(gameTime);
gameClock.Update(mainClock);
playerClock.Update(gameClock);
// Pausing gameClock pauses playerClock too
gameClock.Paused = true;
Full documentation and sample project: GitHub Repository