Part 1 – Creating a Cross Platform MonoGame

PDF for offline use
Related Links:

Let us know how you feel about this

Translation Quality


0/250

last updated: 2017-03

This walkthrough shows how to create a new project for iOS and Android using MonoGame. The result is a Xamarin Studio solution with a cross-platform shared code project as well as one project for each platform. This project will display an empty blue screen when executed.

Overview

MonoGame enables the development of cross-platform games with large portion of code reuse. This walkthrough will focus on setting up a solution which contains projects for iOS and Android, as well as a shared code project for cross-platform code.

When we’re done, we'll have a project that has the proper structure for performing game update logic and game drawing logic at 30 frames per second. It can be used as the base project for any MonoGame project. Our project will look like this when executed:

Adding MonoGame to Xamarin Studio

MonoGame can be added as an add-in to Xamarin Studio. On Mac, select Xamarin Studio > Add-in Manager... . On Windows, select* Tools > *Add-in Manager... . Select the Gallery tab, expand the Game Development category and select MonoGame Addin, then click Install:

⚠️

Note: If the Game Development section does not appear in the Add-in Manager, you can manually download and install the latest version from here: http://www.monogame.net/downloads/. You may need to restart Xamarin Studio for the templates to appear.

Once installed, MonoGame templates will appear in Xamarin Studio, as we will see in the next section.

Creating a new solution

In Xamarin Studio select File > New Solution. In the New Project dialog, click on Miscellaneous, scroll to the General section, select the *Universal MonoGame Mobile application *option, and click Next.

Name the project WalkingGame and click Create:

Now our project will execute just like any other iOS or Android project. The project should run displaying a cornflower blue background:

⚠️

Xamarin Studio on Windows does not include iOS templates. Developers working on Windows need to add all code files to a project-specific Android project or manually add either a PCL or shared code project.

Fixing Android Compile Errors

The current version of MonoGame’s templates includes a few syntax errors in the Android’s Activity1.cs file. To fix these problems, replace the OnCreate function with the following:

protected override void OnCreate (Bundle bundle)
{
    base.OnCreate (bundle);

    var g = new Game1();
    SetContentView((View)g.Services.GetService(typeof(View)));
    g.Run();
}

Summary

This walkthrough covered how to create a cross-platform MonoGame project using Xamarin Studio. The result of this is an empty blue screen. This project can be used as the starting point for any iOS and Android game.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.