Porting your Windows XNA game to MacOS using MonoGame and MonoMac Part 2

This part deals with creating your MonoDevelop project and adding your game files to it. Before proceeding it would be a good idea to get your original Windows game project folder on to your Mac, so you can grab files from it.

Creating your MonoDevelop project

-Open MonoDevelop

-File->New->Solution->C#->MonoMac->Empty MonoMac Project->Name it the name of the final game->Select destination directory->Forward

-You can check the GTK# option if you wish. You could always remove it later. I didn’t need it for my simple 2d game. Hit Ok.

-If you can’t see the Solution Explorer on the left, go to View->Debug and it should appear

-Right-click on the project in Solution Explorer, Add->New File…->General->Empty Class->Name it “Program”->New button

-Replace all the code generated in the new file with the following code and save the file, obviously replacing “MyNameSpace” with your game’s namespace and assuming your main game class is called Game1 (Game1 is the default name given to your main game class when you create a brand new XNA Game project in VC#2010)

using MonoMac.AppKit;
using MonoMac.Foundation;
using MonoMac.CoreGraphics;
using System.Runtime.InteropServices;

namespace MyNameSpace
	class Program
		static void Main (string [] args)
			NSApplication.Init ();

			using (var p = new NSAutoreleasePool ()) {
				NSApplication.SharedApplication.Delegate = new AppDelegate();

	class AppDelegate : NSApplicationDelegate
		Game1 game; 

		public override void FinishedLaunching (MonoMac.Foundation.NSObject notification)
			using (game = new Game1()) {
				game.Run ();

		public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender)
			return true;

-In Solution Explorer, right click on the Solution name->Add->Add Existing Project->Navigate to the MonoGameFramework/ThirdParty/Lidgren.Network/Lidgren.Network.MacOS.csproj file -> Open

-Do the same as above for the MonoGameFramework/MonoGame.Framework/MonoGame.Framework.MacOS.csproj file

-Expand MonoGame.Framework.MacOS project in Solution Explorer. Expand “References” and you should see Lidgren.Network.MacOS. listed there. If not, right click on “References” folder Edit References->Projects Tab->Check Lidgren.Network.MacOS->Ok

-Right click on your Game Project’s References Folder and hit Edit References->Projects Tab
*Check the MonoGame.Framework.MacOS project and hit OK

-In Solution Explorer right click on your game project Add->New Folder->Name it “Properties”

-In Solution Explorer right click on your game project Add->New Folder->Name it “Content”

-Using your Mac’s Finder go into your original Windows project folder MyProject\Properties\ and copy the AssemblyInfo.cs file and paste it to the new Properties folder

-Back in MonoDevelop, right click on your game project Properties folder Add->Add Files…-> AssemblyInfo.cs-> Open

-Go into your original Windows project folder MyProject\Content and copy all the sound files, I only use .wav files, to the new Content folder

-Go into your original Windows project folder MyProject\bin\x86\Debug\Content\ and copy all the .xnb files THAT ARE NOT VIDEO into the new Content folder. (We’ll deal with video files, later in the guide)

-Back in MonoDevelop, right click on your game project Content folder Add->Add Files…-> Select all the files there->Open

-In Solution Explorer, Select all of the .xnb and .wav files in the Content folder at once (select first one, hold shift and push down arrow till you’ve selected them all), then right-click Build Action->Content (this will take awhile, wait for all the items to deselect, except last one, that’s how you know it finished)

-Copy ALL the .cs (except for Program.cs ) and .resx files from your original project into the same directory as Program.cs

-In Solution Explorer right click on the project name and Add->Add Files->Select all the .cs (except Program.cs) and .resx files and hit Open button

-In Solution Explorer, Select all of the .resx files, right-click Build Action->Embed As Resource

-If your old namespace does not match your new one, search your entire project for the old namespace and replace it with the new one that’s in your Program.cs file (it won’t just be in the namespace location, you’ll find the old namespace in the middle of any resx’s cs file for example, change them all). Your best bet is to use MonoDevelop’s Search->Replace In Files…

-In Solution Explorer right click on your game project Add->New File->MonoMac->Empty Interface Definition->Name it “MainMenu”-New button (I’ve also been told that sometimes naming it “MainWindow” works instead of “MainMenu”)

That’s basically it. With a few minor tweaks your game should be able to build and run. Read on…

A few points on MonoDevelop

-MonoDevelop is friggin’ awesome. It has a few minor bugs but they are totally manageable. Here are two that I’ve noticed and their workarounds:

*A bug sometimes occurs where you place the cursor with mouse in your code but the cursor appears on another line, if this happens, use the keyboard to move the cursor around because the mouse will not put the cursor in correct spot. Or you can close MonoDevelop and restart

*I’ve also encountered situation where the Solution Explorer is completely empty. But closing and restarting MonoDevelop fixes this as well.

*Not a bug but sometimes you’ll be prompted about converting line endings because they differ from the policy settings. You can go ahead and hit Convert.

Some more points to hopefully help you save time

*Your main .resx file for your default language should work fine, but .resx files used for other languages will not work correctly at this point, there is a work around for this that I will detail at the end of this guide. Skip ahead and find the “Localization” section in a future part to this guide if you are worried about it. Otherwise worry about Localization later.

*A common staple in Mac applications is the About window. You will not be able to see the About Window correctly as you debug with MonoDevelop, this is one of the last steps. Don’t worry about it for now.

*The application icon for the Finder, Dock, and About Window will not show up correctly as you debug with MonoDevelop. Again this is one of the last steps, don’t worry about it for now.

*If you find your game running much slower in some parts, it might just be bad coding. For example, in my engine I call a method that gets all the color values of every pixel in a sprite. On Windows it ran fine, on MacOS it seemed to be working extremely slowly. I thought at first this was just a limitation of MonoGame or MonoMac, but while trying to come up with a work around I realized that I was actually calling that method 9 TIMES instead of just once. Yes I should be ashamed of myself, and I’m not quite sure why it worked so smooth on Windows, but the point is that I have not noticed any noticeable performance difference between XNA on Windows and MonoGame on MacOS

Overcoming build errors

Ok let’s try to build and see what happens!
-Build->Rebuild MyGame. If you run into build errors, some of the things I did were:

*add References to System.Management and System.Windows.Forms (in the references window under the “All” tab)

*change “new VideoPlayer()” to “new VideoPlayer(this)” or replace “this” with your game class.

Those were the only build errors that I got, if you have others, you can try to start figuring things out on your own. MonoDevelop is very similar to Visual Studio so you can usually right click on a method or variable and select “Go to declaration” which will take you to it’s definition in the MonoGame framework. And/or you can read part 3 of my guide when I start talking about the tweaks you have to make to get the game to run properly. Some of your build issues might be addressed there.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>