MonoGame Demo


Last week I discovered how MonoGame is making it possible to write XNA games for the Windows 8 Metro environment. And I managed to draw a blue screen, which was nice enough, but not much of a basis for a game. So today I thought I’d make a sample project that had all the bits that you need to make your own game, including art assets, using the touch panel, using the accelerometer, drawing text and making sounds.

I’ve made a single, one-stop, demo that does all these things. It also includes the source of the MonoGame code as part of the project. I’ve found this to be quite useful when working out how the XNA implementation works. If you download the zip archive you should have everything you need. Here is how to get started.


You will need three things before you can move any further:

  • Windows 8 Release Preview – this is where you run everything
  • Visual Studio 2012 Release Candidate for Windows 8 – this is where you build your program
  • Visual Studio 2010 for Windows Phone – this is where you create the XNA resources that you want to add to your game

Getting the Files

To get started just download the file from here. This is around 22MB. Before you unzip the file it is a good idea to Unblock it. This will stop Visual Studio from giving you warnings when you open any of the projects. To unblock the file you just have to right click on the file where you have download it, select Properties from the context menu and then click Unblock and then OK as shown in the badly highlighted screenshot below.


Then unzip the files. There are quite a lot of them. Once you have completed the download you will have the whole MonoGame framework and my little test project. Open the folder and find the Visual Studio Solution “MonoGame.Framework.Windows8” and open it. Make sure you open it with Visual Studio 2012 Release Candidate. If you double click the solution you will probably start up the wrong version of Visual Studio (I do) which doesn’t end well.

Running the Sample Program

The solution contains a project called Test Project which runs a port of a Windows Phone demo I wrote that lets you draw lines of dots on the screen using your finger. The dots that you draw will also fall down the screen in a way that is controlled by the accelerometer. You can clear the dots by double tapping on the screen, the game will make a “Ding” sound when you do this. The game also writes some text on the screen.

Resources and Fun

The MonoGame XNA part of things works very well, apart from content. At the moment there is no way of getting Visual Studio 2012 to pre-process XNA content for use in a game. We get around this by creating a Visual Studio 2010 XNA project and using it to produce the xmb files that are read by the content manager when the game runs. The content in the sample program came from existing XNA projects that I had around the place. If you are migrating an XNA game onto Metro you can do the same. The tricksy bit is where you put the xmb files for the game to use. I had no success adding them to the Visual Studio project, instead I had to put the xmb files in the specific directory read by the game when it runs.


Here you can see the path to the AppX\Content folder where I put the XMB files for the sample game. These include the two textures, the font and the ding sound file. If you want to add more content to your game, just drop your files here and then refer to them in the program as you would in any other resource:

protected override void LoadContent()
    // Create a new SpriteBatch, which can be used to draw textures.
    spriteBatch = new SpriteBatch(GraphicsDevice);
demoTexture = Content.Load<Texture2D>("DemoArtwork"); demoRectangle = new Rectangle(0,0,GraphicsDevice.Viewport.Width,
GraphicsDevice.Viewport.Height); smudgeTexture = Content.Load<Texture2D>("Smudge"); font = Content.Load<SpriteFont>("MessageFont"); dingSound = Content.Load<SoundEffect>("ding"); }

You should be able to use my TestProject as the basis of anything that you fancy making.