This is the start of a series of posts about getting started developing games using MonoGame in C# for Windows 8. One thing I think I need to make clear is that MonoGame on Windows 8 does not run on top of Mono, it runs on top of the WinRT C# stack and SharpDX, a free open source library that allows you to access DirectX from C#. This means you don’t have to purchase any Mono licenses to use MonoGame on Windows 8, and MonoGame itself is free and open source. If you decided to port your games to iOS or Android then at that point you would need to license the appropriate Mono tools from Xamarin.
For Windows 8 Store development you’ll need to be running Windows 8. You can do a 90 day trial here http://msdn.microsoft.com/en-US/evalcenter/jj554510.aspx?wt.mc_id=MEC_132_1_4 if you don’t have other access to Windows 8. You’ll also need Visual Studio 2012. There is a free Express version for Windows 8 available at http://www.microsoft.com/visualstudio/eng/downloads#d-2012-express if you can’t get a paid version of Visual Studio 2012. It can install side by side with Visual Studio 2010 if you need both environments.
After Visual Studio is installed, you’ll also need MonoGame. For this series I’ll be using the MonoGame 3.0 Beta that you can install via this link http://monogame.codeplex.com/releases/view/96421. The installer will also install a matching version of SharpDX and any other supporting libraries. As MonoGame 3.0 moves to release I’ll try to update this blog series to use the latest version.
File –> New –> Project
When you install MonoGame it will add two project templates to Visual Studio 2012. So let’s do File –> New –> Project and choose the MonoGame Game (XAML) template. Name it MyFirstGame.
The difference between these two templates is that the one we chose allows you to overlay XAML visual elements on top of your game surface. This is something you don’t want to do indiscriminately since it can impact performance but it’s a great way to be able to add things like the Settings pane flyout and an Application Bar if necessary. It also helps when you want to add XAML based advertising controls. The other template is pure MonoGame and you wouldn’t be able to overlay any XAML elements. I have a hard time thinking of any reason why you would want to use the non-XAML template and I would recommend you always use the template that allows you to mix MonoGame and XAML.
One the game is created you can go ahead and run it. You should see a screen that’s a light blue, known as Cornflower Blue. This is a famous color in XNA development, and some claim it is a reference to dialog in Fight Club. Whatever the reason, I like to call this the “Blue Screen of Life” because it means that everything is installed and configured correctly to start with game development.
I find it useful to take advantage of the Simulator that ships with Visual Studio 2012 when debugging. In the Debug toolbar, where it says “Local Machine” you should be able to select “Simulator” from the dropdown menu.
This option allows you to run a copy of your current environment but run it inside a virtual machine. Some advantages include easily swapping between Visual Studio and the Simulator, spoofing things like location services, taking screen shots, testing different resolutions, and more. Running inside the Simulator looks like this:
If we take a look at the GamePage.xaml you’ll see that it doesn’t look like a normal page in a XAML based Windows 8 Store application. Instead it has a root element of SwapChainBackgroundPanel.
The SwapChainBackgroundPanel is what allows you to overlay XAML on top of DirectX.
The other important file is Game1.cs. This is your game class and all game logic and rendering will either be in this file or in a file called from this file. If you have an existing XNA game, you should be able to take this file as-is and replave Game1.cs with this file and things should “just work”. Actually this isn’t exactly true and you’ll also have to concern yourself with bringing in any Content that the game needs. In the next post we’ll look at bringing in content and drawing something to the game surface.