or, XNA is dead! Long live XNA!
WARNING! Learning in the open™! There are a few moving parts when starting with MonoGame, so I’m just documenting the steps I took.
Microsoft XNA is/was a set of tools and a frameworks that provided a relatively easy way to create games using the CLR, sitting on top of DirectX.
Microsoft stopped active development of XNA around 2011, and last year it became obvious that XNA would be retired. The former XNA home page now redirects to MSDN’s Games development page, which (apart from not actually having any useful information about game development on Microsoft’s platforms) is mainly spruiking Microsoft’s partnership with Unity.
Unity is both a game engine and a component oriented game development environment, with Mono-based scripting using C#. What this means for the average code monkey such as I is that when firing up Unity you are confronted with a drafting board. No comforting
10 PRINT 'HELLO, WORLD!' here folks.
MonoGame is an open-source rewrite of XNA 4 (the last version), using the same namespaces and with support for both DirectX 11 and OpenGL. Since it is based on Mono, it allows applications to be written and ported to most platforms, including PS4, Wii U, Xbox 360, Windows Desktop and Store, Android, iOS, Windows Phone, Mac OSX and Linux. The big player missing from that list is Xbox One, which currently does not support applications targeting the CLR.
<aside> Unity apparently will (soon) support Xbox One so I guess it deploys native code, much like how Xamarin can deploy native code written in C# to target platforms that don’t support the CLR such as iOS. Which begs the question, why not just do the same in MonoGame? A question for smarter cookies than myself.
MonoGame also has some official M$ love with several games published by Microsoft Studio.
Given these weighty credentials, I put the key in the ignition and powered up for a full throttle hello world.
Don’t try this at home.
I cloned the samples repo and just tried to run the
WindowsDX (Windows desktop DirectX) solution. No dice. Couldn’t copy resource files, couldn’t resolve all the referenced assemblies.
MonoGame has some NuGet packages so I pulled them into the project. I got it building but still had the same problem with the resource files.
I then installed MonoGame using the installer. This let me create new projects using MonoGame’s templates, so I created a new project and started following this tutorial series by Tara Walker. The first part went well, which involved showing a simple image on a surface. The tutorial links to an
.xnb file containing the image, which loads correctly. So far so good, I’ve got stuff on the screen, I’m a game developer.
The third part of the series goes through creating that
.xnb file from a source image. This is where I became unstuck.
Images and other assets are relatively easy to use in the web and desktop application space. To add an image to a web site, you drop a JPEG, PNG or GIF onto a server and add a
<img> tag to your markup. To add an image to a WPF, Store, Phone or WinForms application, you add the file to the project as an embedded resource and then use it in a similar way.
Asset management is a much bigger part of game development. There are textures, meshes, sound effects, background music, graphics shader programs and probably a heap of other stuff that I will never understand, and it these assets need to be available to the game code in a way that is efficient and managable. For example, a texture used for a wall may have a number of resolutions, ranging from a very small resolution without much detail for display at a distance to a very large resolution with a lot of detail for display at a short distance.
The content pipeline is a preprocessing step that takes the game assets and converts them into a format suitable for the engine. In MonoGame’s (and XNA’s) case, this is the
<aside> Note that I don’t have a full knowledge of the reasons and techniques used in the content pipeline, this is just my understanding of the ideas.
MonoGame doesn’t have its own content pipeline management system, although it does use XNA’s
.xnb format. For this reason we have to use XNA.
XNA 4 only targets VS2010 so it can be tricky to get it working with VS2013. I found a nice post here, Mr Whitaker has written a script that downloads the XNA installer and sets it up in whatever versions of Visual Studio from 2010 to 2013 that it can find. I went through the script manually and got it going. Here are the steps:
XNAGS40_setup.exe /extract:XNA, this will extract the installer files into a
redists.msi, this installs some more installers to
X:\Program Files (x86)\Microsoft XNA\XNA Game Studio. Yo dawg.
X:\Program Files (x86)\Microsoft XNA\XNA Game Studio\Setup
X:\Program Files (x86)\Microsoft XNA\XNA Game Studio\Redist\XNA FX Redist
xnaliveproxy.msi(this actually failed for me but it hasn’t caused any dramas so far)
xnags_visualstudio.msi. This installs the VS2010 extension, we’ll get back to this one.
XNAfolder in step 4 (possibly order is important)
X:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft
XNA Game Studio 4.0folder. This is the VS2010 extension installed in step 13.
X:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft
extension.vsixmanifestfile in the new
XNA Game Studio 4.0folder (this is in
Program Filesso you’ll probably need to open notepad as an administrator)
Version="10.0"and change it to
%userprofile%\AppData\Local\Microsoft\VisualStudio\12.0and deleting the
Now when you create a new project you should have XNA Game Studio 4.0 templates available. Create a new
Empty Content Project (4.0) and compile it to make sure the content pipeline is working.
As I said above, I also installed the MonoGame binaries, which adds the MonoGame templates to Visual Studio. Download the bits from MonoGame’s Downloads page.