MonoGame For Windows 8 Step 1 – Getting Started

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.

The Tools

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.

image

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.

image

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:

image

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.

image

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.

  • http://www.facebook.com/CromWhoCaresForNothing David Cole

    Bill, thanks for sharing.  Even though I’ve never released an XNA game of my  own, I’ve certainly dabbled with it (and have downloaded several games produced by others with XNA) and have been mourning the decision not to support it in Windows 8.  MonoGame seems like a platform with some real promise.

    • http://billreiss.com/ Bill Reiss

      Yes they’ve done a great job and it keeps getting better, and it runs great on a Windows RT tablet. No hesitations recommending it.

  • http://www.facebook.com/sychris.lee Chris Lee

    Whadaya know, the day I decide to jump into Windows 8 games development, I see your blog linked in the CodeProject newsletter. I’m eagerly awaiting your next blog entry Bill!
    BTW, what are the XNA forums you frequent?

    • http://billreiss.com/ Bill Reiss

      Chris,

      I must admit I don’t go to the forums very often, but I’d recommend the XBLIG XNA forums at create.msdn.com http://xboxforums.create.msdn.com/forums/ and of course Stack Overflow. Also there is the #xna IRC channel on efnet, I used to go there a lot but haven’t in a while, I assume it’s still around.

  • Thefaker

    Fairly sure you DON’T have to buy tools from Xamarin to compile MonoGame apps to run on iOS and MacOSX either, anymore than you do for Windows8 … at least I have done this on MacOSX without buying any. Less sure about iOS, but I think it can be done in a similar way to what I did on Mac.

  • Andrew

    When I choose new project in the MonoGame folder I don’t get the 2 items listed in your screenshot (“MonoGame Game” and” MonoGame Game (XAML)”). Instead I see Android, Content, Linux, OUYA and Windows OpenGL projects.

    Any idea what I can do to get the “MonoGame Game”? Otherwise, I am not sure how to proceed with the tutorial. Thanks.