-
Notifications
You must be signed in to change notification settings - Fork 121
Home
See Change History for a version history of the engine.
SadConsole is pretty simple to get up and running. If you're working with the starter project included in the source code, you can tweak that to test out engine features. However, if you are starting with a new MonoGame or XNA project, you must follow these steps to integrate SadConsole:
- After creating a new project, open the game1.cs or game1.vb source code file
- Build the project so the bin\debug or bin\release folders are created
- Copy the font definition file and the font graphics file to the build directory
- Add reference to the SadConsole.Core.dll to your project
- Add reference to either the XNA or MonoGame libraries to the project
- Add the code below to the three overrides: Initialize, Draw, Update
Before anything can be done with SadConsole, the main engine must be initialized. The initialization routine takes a GraphicsDevice reference object.
At least one font file must be loaded into the engine as the default font. A font is a set of cells representing every character used by your game. The following example overrides the Initialize() method on a Game class:
protected override void Initialize()
{
SadConsole.Engine.Initialize(GraphicsDevice);
// Load a font from the current directory
using (var stream = System.IO.File.OpenRead("IBM.font"))
SadConsole.Engine.DefaultFont = SadConsole.Serializer.Deserialize<Font>(stream);
// Use the font to resize the game window to be 80x30 cells.
font.ResizeGraphicsDeviceManager(graphics, 80, 30, 0, 0);
// Create a console list and set it as the default
var consoles = new SadConsole.Consoles.ConsoleList();
SadConsole.Engine.ConsoleRenderStack = consoles;
//
// This is where you would add any console instances to the ConsoleList.
//
// Finish initialization.
base.Initialize();
}
The Update method of the Game class allows SadConsole to read the mouse and keyboard input devices as well as update any logic behind the scenes of the consoles the engine knows about.
protected override void Update(GameTime gameTime)
{
SadConsole.Engine.Update(gameTime, this.IsActive);
base.Update(gameTime);
}
The Draw method of the Game class allows SadConsole to render the SadConsole.Engine.ConsoleRenderStack consoles. When you create a console, you generally will be adding it to the ConsoleRenderStack.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
SadConsole.Engine.Draw(gameTime);
base.Draw(gameTime);
}