Run MonoGame 3.2 on Mac OS X

MonoGame is wonderful low-level framework for game development. It utilizes power of C# and supports many platforms including Mac OSX. It works smoothly on Windows with VS Express 2013 but require more efforts to run MonoGame project on MacOSX with Xamarin Studio. The great news that Xamarin 5.0 supports NuGet and latest MonoGame was added to NuGet repository. In this post I summarized all issues I met when tried to build MonoGame app. So let’s install Xamarin Studio and start.

At first we have to create empty MonoMac C# project.

Снимок экрана 2014-06-08 в 22.12.30


Once project is created run NuGet package manager and add MonoGame packages. NuGet package manager is opened by clicking on project name.

Снимок экрана 2014-06-08 в 22.16.18

Type MonoGame in Search field and select MonoGame templates and binaries.

Снимок экрана 2014-06-08 в 22.18.53


MonoGame will add Program.cs which acts as runner for Game1.cs template game app. If we try to build it now we will get lots of reference not found errors. Now we have to configure references from MonoGame binary package.

Goto “Edit References” dialog page, open .NET Assembly tab and add MonoGame assemblies from package folder. For our project type we need to get it from MonoMac folder.

Снимок экрана 2014-06-08 в 22.28.33

At this point our project can be built but still will not work. On start we will get an exception that the method can be invoked only from the UI thread.

Снимок экрана 2014-06-08 в 22.31.57

Now it is a time to change main entry point to work with MonoMac. Luckily MonoGame provides good samples on GitHub where we can borrow right startup code for our project.

#region Using Statements
using System;
using MonoMac.AppKit;
using MonoMac.Foundation;

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

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

				// Set our Application Icon
				NSImage appIcon = NSImage.ImageNamed ("Icon.png");
				NSApplication.SharedApplication.ApplicationIconImage = appIcon;

				NSApplication.Main (args);

	class AppDelegate : NSApplicationDelegate
		private Game1 game;

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

		public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender)
			return true;

There are two new items introduced in Program code. MonoMac references and Icon.png for application window. Find your favorite icon and add it to Resource folder.

Снимок экрана 2014-06-08 в 22.45.22

We are almost done but the application still doesn’t work. The last problem with an error about missed MainMenu nib. Open Info.plist and delete MainMenu nib entry.

Снимок экрана 2014-06-08 в 22.59.23

Now build and run. If you did everything correctly the game will start successfully.

Снимок экрана 2014-06-08 в 23.02.37