A reprint from the May 2013 issue of Gamaustra's sister publication Game Developer magazine, this article explains how you can transition your XNA projects to MonoGame. Purchase the May 2013 issue here.
For a long time, the idea of making "real" games using managed languages such as C# was considered lunacy. But things have changed, and managed languages are now proving to be quite viable for making games, thanks in large part to XNA and Unity 3D, with both using C# as their main development language or scripting engine. Many new game devs learned to use XNA in order to get their games on the Xbox 360 and Windows PCs, and even though Microsoft recently announced that XNA will neither see any more active development nor be supported in Microsoft's Metro interface, those devs don't have to start over from scratch. Enter MonoGame, an open-source implementation of the XNA 4 API.
What is MonoGame?
MonoGame's project goal was initially to allow XNA developers to publish their games on iPhone, but the project has grown a lot since those humble beginnings. It now supports a number of platforms, including Mac OS X, Linux, Windows 8, Windows Phone 8, Android, and iOS. For the most part, it is free to use (though you'll need to pay for a license for the Xamarin iOS and Android frameworks) and modify, as all the code is covered by the MS-PL (Microsoft Permissive License). Now, MonoGame's goal is first to produce an XNA-compatible cross-platform API, which can be extended to new platforms as they appear. For example, because MonoGame already supported Android, we were able to add Ouya support to MonoGame in a matter of days.
Once the XNA API is stable, we're planning to extend the API with new features that people would have liked to see in XNA, and extend the API to make it even easier to do certain tasks. For most of the team involved, some of whom have been working on MonoGame for a few years now, this is a long-term project.
Getting Started with MonoGame
First off, head over to www.monogame.net/downloads and grab the latest stable release. At the moment, MonoGame supports Visual Studio and MonoDevelop/Xamarin Studio.
If you want to use Visual Studio: The Windows installer will install project templates for all editions of Visual Studio 2010 and 2012. Particular requirements for your target platform are as follows:
- For Windows desktop, you can use VS 2010 Express or higher, or VS 2012 Express for Desktop or higher on Windows 7 or 8.
- For Windows Store, you will need VS 2012 Express for Windows 8 or higher on Windows 8.
- For Windows Phone 8, you will need Windows 8 64-bit and the Windows Phone 8 SDK. This will install VS 2012 Express for Windows Phone, and can also work with VS 2012 Professional or higher. To use the Windows Phone 8 emulator, your PC needs to meet specific hardware requirements; see www.microsoft.com/en-GB/download/details.aspx?id=35471 for details.
- For Android and/or iOS, you will need VS 2010 or 2012 Professional or higher and Xamarin Business or higher on Windows 7 or 8.
To build content to xnb format, you will also need XNA Game Studio 4.0 or the Windows Phone 7.11 SDK installed. This is a temporary measure until our content pipeline replacement is completed. To install either of these SDKs on Windows 8, you need to have the Windows Games Live client first.
A full list of the prerequisites and download links can be found here.
If you want to use MonoDevelop/Xamarin Studio: MonoDevelop is a free open-source IDE that is available for Windows, Linux, and Mac OS X (www.monodevelop.com). MonoGame is available as a package, which includes the runtime for each platform. You can download this from Codeplex as an .mpack file, and install it via the AddIn Manager within MonoDevelop. Recently, Xamarin has released Xamarin Studio, which is an updated version of MonoDevelop for people wanting to use this IDE. There is also a .mpack file available for that version.
Once you have installed the required package into your chosen IDE, you will be able to create a new MonoGame project. There are a number to choose from, but to get started, you should pick the one that is native to your platform -- for Windows, create a new "MonoGame for Windows GL" application; for Mac OS X, create a "MonoGame for MacOS," and so on. Once you have a new project you will see the familiar Game class that renders the customary CornflowerBlue screen.
Skulls of the Shogun dev 17-Bit used MonoGame to build a Windows 8 version of the game.
Before you start coding, there are a few things you should watch out for. For Windows, all of the templates will work out of the box, but if you want to work on an Android project, you will need Xamarin.Android from Xamarin installed. MonoDevelop/Xamarin Studio does include templates for Mac OS X and iOS, but these will currently work only on an Apple Mac because of the underlying development requirements. For iOS, you'll need to install Xamarin.iOS, and for Mac you'll need to grab MonoMac. Also, due to some issues with the AddIn for MonoDevelop and Xamarin Studio, you will need to download the MonoGame source code and add references to the required MonoGame projects for MacOS, iOS, and Android. (The team is working on getting this fixed.)