TLDR: You can access the source code here.
Sometimes one of the hardest things to do is just get started with something. Over the past couple of years, I’ve taken a few cracks at getting back into game development mostly by looking at xPlat frameworks such as libGDX and MonoGame. One of the really nice things that libGDX has is a Setup Project app that, when ran, generates projects for the different platforms that the framework works on as well as a single place for shared code and the place to put all of your shared resources. This makes it super easy to get started and running your app on all of these platforms (Android, iOS, Windows, OS X, etc). Unfortunately, MonoGame doesn’t have a similar feature. Every time I’ve gotten back into MonoGame this has affected me because when I start development with a cross-platform framework, one of the first things I like to do is make sure things are running on all the platforms I intend to target. With any framework, I think you will probably end up finding things that you need to modify for specific platforms but it’s nice to see a very simple app (I won’t call it a game at this point) running cross-platform.
In order to make it easier on other people who may be trying to tackle the same issue, I spent the time getting the same app running on Android, iOS, and Windows Phone (the three platforms I’m interested in targeting right now). There are several reasons today why this is complicated:
- Version 3.2 of MonoGame (including project templates) has been released for Windows and Visual Studio, but NOT for other platforms (OS X being the one I need).
- There are NuGet binaries you can use but that’s not without it’s own issues.
- The other option, which I used, was to compile the source code from GitHub.
- The Content Pipeline tool isn’t part of the public build yet (or at least it doesn’t seem to be) requiring you to grab the source for MonoGame and compile it. The Pipeline tool is really important if you want to compile your resources into the optimal format for each platform (recommended) and prior to the MonoGame folks making a tool, you had to use the old XNA Content project stuff (nightmare if you don’t already have a machine set up with it).
- For more on the Content Pipeline tool, check out this video from Xamarin Evolve.
- Since this isn’t in the public build, I had to compile it from source too.
- There are two different ways to share code (i.e. put all your game code in one place) with MonoGame (and Xamarin): PCLs and Shared Projects. They both have their pros and cons but I decided to use Shared Projects. This allows you to create code which is compiled for whatever platform you’re currently building for and you can do #if to put platform specific code. While the shared project type is supported by VS 2013 Update 2, you can’t actually add a reference to a shared code project (at least not a Windows Phone one). To get around this there is Visual Studio Extension called the Shared Project Reference Manager that you just install and you’re ready to go.
It might seem like the first two bullet points are bashing the folks who work on MonoGame but that’s far from how I feel. MonoGame is a free framework and the people that work on it seem to do it on a volunteer basis. I have nothing but respect for these people and think they’re doing a great job. I, like everyone else wish they could do it faster / become rich for their efforts / make everything work just as easily on OS X, but in the meantime, I’ll do what I can to bridge some gaps.
The Source Code
The code for the starter proejct is available on GitHub and comprises the following:
- Solutions for Xamarin Studio (with iOS and Android projects) and Visual Studio (for Windows Phone)
- A Shared Project with the Game class in it
- iOS, Android, and Windows Phone 8.1 projects which all reference the Shared Project and use it’s Game class
- The Android project is targeting 4.2
- You might need the above mentioned Shared Project Reference Manager for the WP project to compile.
- A local libs folder that contains iOS and Android MonoGame framework assemblies built off the Dev branch
- The Windows Phone project is referencing the DLLs for MonoGame installed with the VS 2013 installer for MonoGame
- Assets for each platform (only the Windows Phone version is compiled into an XNB for now)
Running the app currently works on each of these platforms and shows the MonoGame logo. This is laughably far from being a game you could run or do anything with but it’s a good template for starting out. Hopefully this provides a jumping point for other people to work on cross-plat games.
2 Comments
Mike-EEE
Shared Libraries and compiler conditionals... yuck! Well... it could be worse. Thanks for sharing this. It's the only resource/reference I could find on the matter.
Chris
Happy it was helpful. But yes, what a mess.