Managing cross-platform targets/compatibility with Monogame

by artganify   Last Updated June 09, 2015 00:05 AM

I recently started using Monogame for the first time because of it's cross platform compatibilities and heavily active development. The first thing I did is installing the whole framework using their provided installer, but as soon as I wanted to make my first Monogame project, I noticed the following:

Although being cross-platform, there is no real 'Monogame' library. The framework ships with multiple assemblies for several platforms, each with their own dependencies. This is reflected both in the Visual Studio project templates as well as for the nugets they provide.

Now I'm wondering: Is there a straightforward way to just develop with the Monogame framework 'itself' in the first place, and then deciding on platform etc. later by using build targets and conditional compilation? Or do I just have to reference every assembly and it will work out of the box? What's your approach when developing with Monogame for different platforms? Making a .NET project for every target platform?

Their documentation unfortunately doesn't describe the different platform assemblies. They are just there, ready to be used with the infomation that Monogame IS cross-platform compatible.

Answers 2

Monogame game is cross-platform compatible, but not in the sense that you just magically click and it will work. In most cases, you are going to need to tweak individual builds, in order to get them to function properly in each environment.

If you consider supporting iOS or Android, you are going to have to look into the xamarin dependencies as well, which are not even part of the Monogame framework at all.

Fortunately, most of the code will just work. It is a matter of getting the builds to compile and work as intended on each environment. There will almost always be at least some minor issues, you will need to compile and try it for each supported environment.

June 08, 2015 21:35 PM

In Monogame, the source code of your game is the only thing that is identical for every platform. Of course you would have to change how you handle inputs for every platform (for example windows doesn't have touch) and how you calculate the screen size (mobile doesn't have multi-monitor setups). If you chose to use the #IF __ANDROID__ and #IF WINDOWS keywords in your code and inside your visual studio project, then you will basically have a common source code folder and you will be able to copy paste it between projects to bring them up to date.

Typically, the best way of developing games is to first develop it for windows Desktop and then when you are finished developing your game, spend a couple of minutes making an Android (or any other) project and setting it up. This is because Desktop projects compile so much faster.

There is no reason to worry about multi-platform until the moment you are ready to deploy your game. Note that you will need a 25$ license from Xamarin to compile your game for Android/iOS. That license lasts for 1 month, but you actually only need it just for the few seconds that it takes to compile (if you are not planning on adding content to your game and having to re-compile at least). The free trial version of Xamarin only produces .apk (and the equivalent for iOS) which last for 24-hours.

As for the dependencies, here is how my project looks like when I build from Monogame's source code. Windows DirectX (on the left) and Android (on the right). Its pretty straight forward. Monogame.Framework.Windows.dll and SharpDX.dll(s) for windows. And Monogame.Framework.Android.dll and OpenTK.dll for Android. You would be able to compile these 2 projects without having anything Monogame related installed. Because I reference the dlls such as SharpDX.dll locally (I have placed them in a SharpDX/ folder inside my Monogame.Framework.Windows library-project).


June 08, 2015 21:58 PM

Related Questions

Monogame on OS X in Visual Studio Code

Updated April 05, 2016 09:05 AM

Monogame project runs in VS but hangs when run via .exe

Updated February 16, 2016 00:17 AM

Monogame new project lag in 1 second intervals

Updated November 09, 2016 08:05 AM

Monogame Per Pixel Collision scale texture

Updated July 24, 2018 07:13 AM