This article describes how to use SadConsole from a Visual Studio MonoGame template.

  • If you’re using a MonoGame template to create a new project, which auto-generated your game1 code file, follow these steps.
  • If you do not have the MonoGame SDK installed, you should create a new blank .NET project by following the directions in the Create a new SadConsole project article.

NOTE
SadConsole for MonoGame targets .NET 4.6.1. You may use a higher version if necessary.

  1. After creating a new MonoGame project, open the game1.cs or game1.vb source code file

  2. Right-click on the project and click Manage NuGet Packages.

  3. Search for SadConsole.Starter and add it.

    nuget preview

    TIP:
    If you’re using Linux, NuGet may not setup your project correctly. Look at the folder containing your project. Add any .font and .png as project references and set them to Copy to output folder.

  4. Open up your game1.cs file.

  5. Change the base class from the MonoGame Game class to SadConsole.Game

    1
    public class Game1 : SadConsole.Game
  6. Change the constructor to initialize SadConsole. Provide the font and width/height of the game window in cells.

    1
    public Game1() : base("IBM.font", 80, 25, null)

Initialize

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
protected override void Initialize()
{
// Generally you don't want to hide the mouse from the user
IsMouseVisible = true;

// Finish the initialization of SadConsole
base.Initialize();

// Create your console
var firstConsole = new SadConsole.Console(60, 30);

firstConsole.FillWithRandomGarbage();
firstConsole.Fill(new Rectangle(2, 2, 20, 3), Color.Aqua, Color.Black, 0);
firstConsole.Print(3, 3, "Hello World!");

SadConsole.Global.CurrentScreen.Children.Add(firstConsole);
}

Example game1.cs class

This class shows using the SadConsole Engine Component to initialize MonoGame

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SadRogueSharp
{
public class Game1 : SadConsole.Game
{
public Game1() : base("IBM.font", 80, 25, null)
{

}

protected override void Initialize()
{
// Generally you don't want to hide the mouse from the user
IsMouseVisible = true;

// Finish the initialization of SadConsole
base.Initialize();

// Create your console
var firstConsole = new SadConsole.Console(60, 30);

firstConsole.FillWithRandomGarbage();
firstConsole.Fill(new Rectangle(2, 2, 20, 3), Color.Aqua, Color.Black, 0);
firstConsole.Print(3, 3, "Hello World!");

SadConsole.Global.CurrentScreen.Children.Add(firstConsole);
}
}
}

Next steps

Now that you have the project created and working, check out the existing tutorials. These will walk you through the basics.

⬆︎TOP