Repository navigation
Game Class
The Game class is the center of a VOID application. It owns the native window, selected renderer, timing, main loop, and application lifecycle.
You can use Game directly, but most games inherit from it and override the lifecycle methods.
A VOID game follows four main hooks:
| Method | Purpose |
|---|---|
OnEnter() |
One-time setup before the loop starts |
OnUpdate(FrameTime) |
Game logic and input |
OnDraw(FrameTime) |
Rendering |
OnExit() |
Final game-owned cleanup |
Example:
public sealed class MyGame : Game
{
private Texture _logo;
private SpriteBatcher _batcher;
public MyGame(GameSettings settings) : base(settings) { }
protected override void OnEnter()
{
_logo = AssetManager.Instance.Load<Texture>("Graphics/logo.png");
_batcher = new SpriteBatcher();
}
protected override void OnUpdate(FrameTime frameTime)
{
// Update game state.
}
protected override void OnDraw(FrameTime frameTime)
{
_batcher.Begin();
_batcher.Draw(_logo, new Vect2(100, 100), Color.White);
_batcher.End();
}
protected override void OnExit()
{
_batcher?.Dispose();
}
}var settings = GameSettings.Instance
.SetAppCompany("MyStudio")
.SetAppName("MyGame")
.SetWindow(1280, 720)
.Build();
using var game = new MyGame(settings);
game.Run();Build() must be called before the Game is constructed.
OnUpdate and OnDraw receive the current FrameTime. FrameTime owns VOID's timing state and keeps the full timing context together instead of passing standalone delta values around the engine.
Use DeltaTime for frame-rate-independent gameplay movement:
position +=
velocity * frameTime.DeltaTime;Useful timing values include:
float scaled =
frameTime.DeltaTime;
float real =
frameTime.UnscaledDeltaTime;
TimeSpan total =
frameTime.TotalTime;
float alpha =
frameTime.Alpha;TotalTime accumulates the engine's clamped real outer-frame time and is not multiplied by TimeScale.
Timing values follow the current engine phase:
- In fixed timestep mode,
OnUpdatesees the configured fixed interval throughElapsedTime,DeltaTime, andUnscaledDeltaTime. - Before rendering, VOID switches
FrameTimeto the actual elapsed time of the current rendered frame.OnDrawand automatically updated cameras therefore see real rendered-frame timing. - In variable timestep mode, update and rendering both use the actual elapsed frame time.
VOID may run more than one fixed update before a draw when the accumulator needs to catch up. Rendering still occurs once per presented frame.
Alpha can be used to interpolate visual state between fixed updates.
The active window is available through:
Game.Instance.WindowFor example:
if (!Game.Instance.Window.IsFocused)
{
// Game window is not focused.
}Runtime window changes are queued and then applied:
Game.Instance.Window
.SetTitle("New Title")
.SetSize(1600, 900)
.ApplyChanges();See Window & Displays.
VOID includes an embedded default SpriteFont:
var font = Game.Instance.Font;This is useful for debug text and simple UI without loading a custom font first.
VOID exposes the resolved application paths through the game instance:
string root = Game.Instance.ApplicationFolder;
string logs = Game.Instance.ApplicationLogFolder;
string saves = Game.Instance.ApplicationSaveFolder;
string config = Game.Instance.ApplicationConfigFolder;
string temp = Game.Instance.ApplicationTempFolder;Create long-lived objects such as batchers in OnEnter, reuse them during the game, and dispose objects your game owns in OnExit.
Avoid allocating a new batcher every frame.
Home · Getting Started · Rendering · Custom Renderers · GitHub · Report an Issue
Built with VOID Engine · MIT License
- Coroutines
- State Machine
- Save System
- Pathfinding
- Logging
- Beacon Manager
- Beacon Event System
- Discoverable System
- Instance Helper
- BeaconManager Extensions
- BeaconHandle Extensions
- Enum Extensions
- String Extensions
- Int Extensions
- Float Extensions
- IEnumerable Extensions
- Random Extensions
- Sound Extensions
- Font Extensions