Skip to content

SadConsole GameHost.Screen: Overview and startup

The SadConsole.GameHost.Screen property is one of the most important properties in SadConsole. It determines what’s displayed and what receives keyboard and mouse input.

GameHost.Screen represents the consoles and surfaces displayed to the user. It’s the single root object; all other objects are children of it. Objects can have unlimited children at any depth.

Swap GameHost.Screen to transition between parts of your game. For example, when your game starts, show a title screen with all its logic. Based on the user’s selection, swap GameHost.Screen to an instance that represents the settings menu or the game itself.

The game configuration object sets the startup screen.

Create a class that inherits from IScreenObject and configure it with your consoles, surfaces, and input handling code. Then, call the SetStartingScreen<TRootObject>(Builder) configuration method with your type. Your startup code assigns SadConsole.GameHost.Screen automatically through this configuration.

Configuration setting

using SadConsole.Configuration;
Game.Configuration gameStartup = new Game.Configuration()
.SetScreenSize(120, 38)
.SetStartingScreen<RootScreen>() // Startup object type is here
;
Game.Create(gameStartup);
Game.Instance.Run();
Game.Instance.Dispose();

Starting screen type

class RootScreen : ScreenObject
{
public RootScreen()
{
// Code here to create consoles, objects, and arrange them.
// Each object should be added to the Children collection.
}
}