Building games for Windows 8 with MonoGame - Introduction (Part 1)

View all articles
Article Image

This is the first part in a series of tutorials to show you how to build and release games for Windows 8 with MonoGame - the open-source version of Microsoft's deprecated XNA. If you've used XNA before then MonoGame will come easy to you. The framework is almost identical and even the namespaces are the same. The only real difference is the lack of content pipeline for importing your assets into the game. The MonoGame team are currently hard at work to overcome this limitation but in the meantime I'll show you a simple technique to get round this problem.

In this tutorial series I'm going to cover the following topics:

  • Setting up a project
  • Rendering and dealing with different screen resolutions
  • Dealing with touch input
  • Adding a game state system
  • Importing assets into the game
  • Adding sound
  • Creating a simple particle framework
  • Dealing with Windows 8 features such as snap view
  • Publishing to the Store

I'm also open to covering other topics or elaborating further on anything I may have skimmed over or missed out altogether. Just leave a comment below!


This series is going to cover the above topics whilst building a fully featured game called Rocket Command. This is a simple clone of the classic Atari title Missile Command that I created for this series. It's available to download from the Windows Store at



First things first you'll need to have a copy of Visual Studio 2012 running on Windows 8. If you're a student you should be able to get both of these for FREE with DreamSpark. I have also written a guide to installing a dual-boot system for Windows 7 And Windows 8 if you're not ready to give up on Windows 7 yet. If you're not a student then you can get a copy of Visual Studio 2012 Express for free from here. This version of Visual Studio is still very powerful and will do everything we need it to.

Next you're going to need to download MonoGame itself. Being an open-source project there are many different branches available. However you can get the latest stable build from here (as of time of writing is 3.0.1).

A reasonable knowledge of C# is also expected. I'll try to cover each bit of code in depth but will expect you to know the basics such as ints, floats, functions and classes.


Once you have all this installed we need to create a New Project in Visual Studio. In the dialog select MonoGame under C# from the templates and you should be shown the following options:


As you can see a number of templates are given to us for a variety of purposes. This will make our code very easy to port to other platforms later on. The MonoGame team reckon that this will increase your code re-use from a normal amount of about 60% to at least 80%. This is a significant help. For our purposes we are going to select the Windows Store template and give it a name of "Rocket Command" (there's also a Windows template with XAML which can be useful for things like adding adverts but we're not going to use that here).

This will set up a basic framework for the game and if we select run now (press F5) we'll see a nice cornflower blue screen! For anyone who has used something like OpenGL or DirectX before you will appreciate that this normally takes some time to set up. MonoGame sorts out all that boiler plate code for you so you don't have to bother. When we pressed run it ran the game on our local machine by default. But we'd like to test it on a few different resolutions and machine types to make sure that our code is as robust as possible. To do this we can select to debug on the Simulator that comes with Visual Studio 2012. Just select the arrow on the drop down box for debugging and select simulator.


If we run the game now we should be shown a simulator running our game.


This gives us a few options. By default the mouse cursor is selected but we can simulate using touch as well as rotating the display, changing the resolution and using the GPS. All cool features.


If we have a look in the Solution Explorer you will see 2 main C Sharp files - Program.cs and Game1.cs. In addition to this MonoGame sets up some Windows 8 features for us. It has created an assets folder for us with basic templates for our game logos. The Packade.appxmanifest file also sets important attributes for our app. We'll cover both of these in a later tutorial.


public static class Program
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
var factory = new MonoGame.Framework.GameFrameworkViewSource<Game1>();
The Program class is the main entry point for our application and is very simple. All it does is create an instance of the Game1 class and run it. We can generally ignore this class as the Game1 class is where everything happens.


This class is going to be the main starting point for our game. It's going to follow a common design pattern in games development. It separates our code in to logic and rendering code, called Update() and Draw() in MonoGame. This loop works by first running some initialisation code before entering a loop where the game alternates between updating the game logic and drawing our assets. It will continue to do this until the game exits.


The Game1 class has created a few stubs for us already. The important ones are

  • Initialise(). This function is for calling any required initialisation code required before the game is run. I will not make use of it in this tutorial series.
  • LoadContent(). LoadContent is called once per game. The idea is to load all of the content we need in this function. We do not want to be loading assets, which can be potentially time consuming, at run-time in case the game slows to a crawl.
  • Update(). This is where all of our game logic such as dealing with input and moving objects will go.
  • Draw(). This is where we will draw all of our game objects.

In the next part we'll look at how to render sprites with MonoGame and to deal with the problems of different screen resolutions and aspect ratios.

Post a comment
Your Screen Name
Your Email Address
Your Comment