Cross-Platform Game Development with Xamarin and MonoGame

Published July 02, 2013 by FourBros Studio, posted by gdarchive
Do you see issues with this article? Let us know.
Advertisement
FourBros Studio has been continuously developing Taptitude with weekly releases for over two years. Creating and testing updates at such high frequency has been a major challenge for us during this time, and recently we've expanded support for Taptitude from our home on Windows Phone to other platforms including Windows 8, Android, and iOS. Creating and testing updates at the same frequency but across 4 different app stores and operating systems simultaneously required us to focus on building a cross-platform solution for Taptitude.

Goals of Cross-Platform Solution

Around November, 2012, we began making plans to port Taptitude to other operating systems and app stores. We knew this would be more than a simple "port job" because of Taptitude's continuously evolving nature. It wasn't sufficient to just get Taptitude running on these other platforms, we needed to create a sustainable cross-platform solution that would allow us to continue to evolve Taptitude. Our primary goal was to have Taptitude running on Windows Phone, Windows 8, Android, and iOS with feature parity across all platforms. This means that when we add a new feature, it appears on all platforms at roughly the same time. We also made it a goal to maintain our existing update frequency (about one update per week). We believe having frequent updates with new content and features has many benefits to our customers. To accomplish these goals, we needed to use 99% identical code within all versions of Taptitude which meant targeting a common framework that behaves the same across platforms.

Xamarin and MonoGame to the Rescue

Given that Taptitude started out as a C# XNA game on Windows Phone, maintaining 99% shared code across all platforms would be out of the question without solutions provided by Xamarin and the MonoGame project. fig1.png Xamarin is a set of tools that allows a developer to write C# code and make use of .NET libraries while targeting iOS, Android, Mac, or even Windows. It is like an identical replacement for Microsoft's .NET platform but it's capable of targeting other operating systems. It also wraps the native iOS or Android APIs into C# libraries so you can make use of native OS capabilities if you do wish to have platform dependent code. MonoGame is an open source implementation of Microsoft's XNA Framework. XNA framework is the library game developers have used on Xbox and Windows Phone for years. With MonoGame's implementation it is possible to have the same XNA code work across operating systems (in conjunction with Xamarin's cross-platform .NET replacement). Combining Xamarin and MonoGame, we were able to establish Windows 8, iOS, and Android versions of Taptitude while sharing more than 99% of code between each version, including the Windows Phone version.

Our Experience with Xamarin

Overall we were very impressed with Xamarin. It provided essential capabilities that we needed to get Taptitude running on Android and iOS. Xamarin for Android provides a multitude of key features that we relied on. It allowed us to compile C# code and use .NET base libraries while targeting Android. Xamarin also allowed us to debug live Android devices using Visual Studio. The Android app project type that Xamarin provides does a nice job of automatically generating your applications AndroidManifest file where things like permissions and other metadata are set up (something that is very easy to get wrong when done manually). Xamarin for Android provides a very powerful way of accessing Java libraries from C#. It lets you create a new Binding project, point it at a .jar (Java library package) and it will automatically build and generate the C# API bindings allowing you to access native Java libraries from C#, such as Google AdMob APIs for advertising. Finally, Xamarin for Android takes care of packaging your app to upload to the Google Play store. Once the app is ready to publish, it just takes a few clicks to create the final package that can be uploaded and made available to everyone on Google Play. Later, we used Xamarin for iOS to port Taptitude to iPhone, iPad, and iPod Touch. This experience was a little rockier for us as the integration of the Xamarin tool chain definitely had some rough spots. To use Xamarin on iOS you have to have a Mac build server (this is more a limitation of the way iOS apps are built). Xamarin's native iOS compiler had trouble building Taptitude due to how much code we have (80+ mini-games in one binary) and was never able to produce builds for iOS devices that could be debugged. We could produce "release" builds that ran on the device but without a debugger attached it made the development process much harder. We had to rely on the iOS simulator for debugging live code which was not ideal. Fortunately for us, Taptitude is 99% identical code on all platforms and so most of the debugging could be done on a non-iOS device but for the few iOS dependent features (advertisements and in-app purchase support) this limitation caused us some pain. Xamarin has an excellent support system for responding to these kinds of issues and providing work-arounds when available, and they actively update the software with fixes and improvements to the tool chain, so even by the end of our porting efforts things were improved and working more smoothly for us on iOS. Despite the few problems we had initially with Xamarin for iOS, in the end we were able to use it to produce a version of Taptitude that simply would not have been possible without Xamarin. While Xamarin is a very powerful cross platform development tool, it comes with a price. Current pricing ranges from Free (for small apps with limited features) to $1899.00 per developer, per platform, for full Enterprise level support. We opted to go with the "Business" license which is currently $999.00 per developer, per platform, and offers the set of features we need (in particular Visual Studio support and unlimited app size). The price wasn't really an issue for us because we knew there wasn't any other viable way of porting Taptitude to iOS and Android other than using Xamarin and at the same time Taptitude had already proven successful on Windows Phone so we were confident that the iOS and Android version would quickly recoup the costs of the Xamarin licenses. Summary:
  • Xamarin was the key factor that allowed us to port Taptitude to iOS and Android
  • It provides powerful features for binding to native libraries and access to the native OS APIs
  • Integration with Visual Studio is a huge plus for any existing Windows Phone or Windows 8 developer looking to port to iOS or Android
  • There are some toolchain issues and limitations on the iOS version of Xamarin, but improvements appear to be coming rapidly.
  • The licence is priced reasonably with multiple tiers supporting indie/hobbyists up to professional enterprise teams.

Our Experience with MonoGame

While Xamarin provides the foundation for writing C# code in a cross-platform way, Taptitude also has a major dependency on Microsoft's XNA framework. The XNA framework provides a set of low level capabilities that any game would need, such as graphics rendering, gamepad/touch input, content pipeline, and primitive math types. Unfortunately, Microsoft seems to have abandoned XNA going forward. Microsoft maintains support for XNA on Windows Phone but even in the most recent version of the operating system (Windows Phone 8), XNA is only available for "legacy" Windows Phone 7 applications. In other words, the new Windows Phone 8 features cannot be accessed through XNA as it is limited to Windows Phone 7 applications only, and Microsoft didn't bring XNA into their Windows 8 app ecosystem. This meant that we needed a replacement for XNA in order to even port to Microsoft's other platforms like Windows 8. Luckily for us, there is an active community of indie developers and enthusiasts who have created the MonoGame project which acts as a drop-in replacement for XNA and has support for Windows 8, iOS, and Android (amongst other platforms, including Windows Phone 8). MonoGame is an excellent way to take an XNA game and get it up and running on a number of other platforms. MonoGame did, however, have some bugs and compatibility issues on some of the platforms we ported to. These were usually minor bugs, memory leaks, or performance bottle necks that Taptitude's large code-base happened to expose. Fortunately, due to its open source nature, we were able to transparently disclose these issues, pick up fixes for them, and in a few cases contribute fixes of our own back into the project. MonoGame continues to get better over time and there is a lot of potential for the framework to go beyond what XNA was ever able to do. Summary:
  • MonoGame is a drop-in replacement for Microsoft's XNA Framework
  • Allows XNA games to run on almost any platform with C# support (and with Xamarin that includes iOS and Android)
  • Free to use and open source

Conclusion

For anyone looking at cross platform game development on mobile platforms, Xamarin is an excellent consideration. If using C# is a priority, then using Xamarin is a no-brainer for these cross-platform scenarios. For game developers in particular, MonoGame is especially attractive as a lightweight cross-platform rendering solution (with the added benefits that come with the XNA framework such as input and math libraries). When paired together, Xamarin and MonoGame provide a solid basis for building cross-platform games. Taptitude can now reach the full mobile market and we're set up to continue evolving Taptitude rapidly in a platform independent way.
Cancel Save
0 Likes 1 Comments

Comments

4thworld

Great article! thanks for your contribution!

July 02, 2013 03:32 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!

Building a cross-platform solution for creating and testing updates across 4 different app stores and operating systems simultaneously

Advertisement
Advertisement
Advertisement