Using MonoGame to port an XNA game to Windows Metro

When I started this blog, over a year ago, I thought “I’m going to make lots of informative posts, share stuff with the community, and be a good guy”. Instead I wrote a whole bunch of bullshit that was useful to nobody.

That’s going to change today. This post, teaches you how to port your XNA game to Windows Store using something called MonoGame. I’m going to go through, step-by-step, using The Rise of Gaddafish as an example. 

Prerequisites
This is a list of stuff I assume you have already got. If you don’t, go get them.
Windows 8
Visual Studio 2012 or Visual Studio Express 2012 (the free version of Visual Studio).
MonoGame 3.0 BETA
–  A finished XNA project.

There’s no link to the last prerequisite, that’s because you have to make it yourself. If you don’t have a finished XNA game, this tutorial isn’t for you. I suggest you go off an make an XNA game first, or you could write a Windows 8 game from scratch.

Create the project

With that all done, let’s begin our adventure. Fire up the best IDE in the world, Visual Studio 2012. File –> New Project –> Visual C# –> MonoGame Game.

If you are stuck at this point, then you probably are not a very intelligent purpose. Perhaps game development isn't for you?

Give it whatever name you want. I chose GRODG3, which is short for Get Rich or Die Gaming 3. If you can’t find the template, you probably messed up installing MonoGame. Go fix that.

Alright, you have a new MonoGame project. Press F5 and it will build and run, and you’ll experience the beauty of a colour known at Microsoft as ‘Corn Flour Blue’.

Import Your Code

This step is pretty simple, you could probably do this without reading what I have written. Right click on your project’s name in the solution explorer. Choose Add –> Existing Item…

Navigate to the folder that contains your XNA Game’s source, and select every single .CS file.

You'll notice I don't like to work past 12.00 AM

Purchase every single Baller Industries game

This step is vitally important. Log onto Xbox Live and buy Get Rich or Die Gaming, Rock Bottom, Let’s Get Fiscal and The Rise of Gaddafish. It’ll set you back $4. Next, fire up your Windows Phone, and buy Virtual Kelvin. Finally, get out your iOS device and buy Get Rich or Die Gaming. That’ll set you back $6.00, but trust me, it’ll be the best six dollars you spend.

The Microsoft certification team will know if you don’t follow this step. They’ll call up Steve Ballmer and he’ll say “I don’t believe it. This jerk went through Angus Cheng’s tutorial, but didn’t even buy one of his games. There’s no way I can certify their game. In fact I am so angry (and bald) that I reckon we should send over a few trojans to their computer. Also let’s make sure this guys photos on Facebook always come out badly.”

Like I said, $6.00 well spent.

Import the Content

Next up, we want to smash in all the textures, audio files and whatever else you have in your game. I only have textures and audio files, so that’s all I’m going to teach you to import.

MonoGame doesn’t have a Content Pipeline. This means, it cannot convert art assets to XNB files, it deals with the XNB files directly. This means we import the XNB files to your project, instead of importing the PNGs/JPGs/WAVs files. This makes it a bit annoying to develop a MonoGame Game from scratch. You can do it, but it is fiddly.

Alright let’s get to it:

1. Create a folder in your project and name it “Content”.
2. Mimic the file structure you used in your XNA Game project.

Alright, the file structure is identical. Now it’s time to fill those folders with XNB files. You should find them in your XNA Project’s bin/Content or bin/Release folder. You basically want the latest XNB files, the one you use in your final version of your game. I never change my build type to Release, so my latest XNB files are in the bin/Content folder.

All you have to do is go through and import the XNB files from the XNA Project, to their corresponding folder in your MonoGame project.

Alright that’s done. Basically you should have some folders, and some XNB files in the folders. You should have the same number of folders and XNB files in your XNA Project, as you do in your MonoGame Project.

Next you need to tell Visual Studio 2012 to copy the XNB files to your output directory. This is very annoying, you need to go through every single XNB file and in Properties, set it’s build action to “Content” and set Copy to Output Directory to “Copy if Newer”.

That should do it. If you are lucky, an haven’t used certain features in XNA, your project might build and run. The Rise of Gaddafish doesn’t though, and that is because I used XACT to manage my audio.

Getting the code to Build

There’s a few issues I came across, and you’ll probably come across some of these as well. The first issue is MonoGame’s mainline is different to XNA’s mainline.

Simply replace XNA’s main line function with MonoGame’s main line function. At this point your code may run. Mine didn’t I had to remove all reference to XACT. Next I had to change the way I referenced art assets. If I referenced an art asset like this:
“GameObjects//gaddafi_door_open”

I had to change it to
“GameObjects/gaddafi_door_open”

Basically I needed to change all double back slashes to single back slashes.

Houston, we have lift off! That’s great, but there is still a lot of work to do before The Rise of Gaddafish can be submitted to Steve Ballmer for certification.

Replacing XACT with SoundEffect

MonoGame doesn’t support XACT, in a //BUILD/ video they talked about why, but I have forgotten why. Go watch the video if you want to find out why.

1. Remove all reference to XACT. For me this means commenting out a lot of code. Basically code that doesn’t compile.
2. Implement the functionality you used in XACT. This is especially annoying for me, because I used lots of built in XACT stuff. Like looping audio, sound effect changing, muting certain categories. What a pain in the ass.
3. Get all your XACT assets, and convert them into XNB files. Then import them into the Content folder.

Splash Screens

When your game launches, you are greeted with a grey background, and a box with an x in it. You probably don’t want that, I’m not 100% sure, but I suspect Microsoft will not allow your game through certification unless you replace the default splash screen. This should be pretty easy, and it is. For me, I want to use a black background instead of a grey one, and I want to use the title from my game’s box art.

You need to provide a splash screen for three different resolutions.
1. SplashScreen.png with a resolution of 620×300
2. SplashScreen.scale-100.png with a resolution of 620×300
3. SplashScreen.scale-140.png with a resolution of 868×420
4. SplashScreen.scale-180.png with a resolution of 1116×540

Insert these four files into your Assets folder. It might seem weird that you have to provide four images, for three different resolutions. It is strange, and I have no idea why this is the way things are done. I guess I could investigate further and find out why, but it’s just a fucking splash screen.

Next up, let’s change the background colour to black. Open a file in your project called Package.appxmanifest, under the heading Splash Screen choose a background colour of #000000.

Open

Angus