Porting an XNA Windows Phone Game to Android


This article uses JMA’s gaming software to demonstrate these features. To download the games, please click here.

This article uses a sample 2D shooter game with MonoGame on Android. Click here to download the sample project.


You need to download Visual Studio 2010 Professional or higher. You need Mono for Android.

Set-up and Sample Game

Go to this site:


Scroll to the bottom and download the Windows Phone project.

Open the solution.

Right click the solution > add > new project > Mono for Android > Mono for Android application


Here is my file structure:


Here is my solution:


Lib has two assemblies; Lidgren.Network.Android and MonoGame.Framework.Android. These are available with the download. You can also download the MonoGame source, compile MonoGame.Framework.Android and ThirdParty/Lingren.Network.Android.

In your ShooterMonoAndroidApplication, add a reference to the two DLLs in the Lib folder. In the add reference window, add OpenTK. Here is the final result:


Adding Code Files

Right click ShooterMonoAndroidApplication > add > existing item. Navigate to the Shooter project and add all the files (except program.cs) as links:


Adding Images

In ShooterMonoAndroidApplication, create a folder under Assets called Content. Navigate to Shooter\bin\Windows Phone\Debug\Content. Add the XIB files are links. In ShooterMonoAndroidApplication, select all the XNB files. Make them Android Asset > Copy if newer:


Adding Music and Sound Effects

Make a folder under Content called Sounds. Music must be in MP3 format. SoundEffects should be in WAV. Add them as links. Here is the end result:



The shooter project has no XML files, however, you other games might use them. You need to use the asset manager to find this data. Here is some sample code:

            XElement doc = XElement.Load(Game.Activity.Assets.Open("Content/Gameplay/LevelDefinitions.xml"));

            var query = from a in doc.Elements("level")
                        select new
                            EnemyCount = (int)a.Element("EnemyCount"),
                            BonusCount = (int)a.Element("BonusCount"),
                            LevelNumber = (int)a.Element("LevelNumber"),
                            LevelLength = (int)a.Element("LevelLength"),
                            LevelPurchaseable = (bool)a.Element("LevelPurchaseable")

Make them Android Assets, copy if newer as shown above.

Conditional Comments

My Android phone has a bigger screen than my Windows Phone. I need to make the background bigger on Android by adding this code:

            spriteBatch.Draw(mainBackground, Vector2.Zero, Color.White);

            spriteBatch.Draw(mainBackground, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1.3f, SpriteEffects.None, 0);

Game File

Game1 is usually the name of your game class. If not, change Game1 in your Activity1.cs file:

using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Microsoft.Xna.Framework;

namespace Shooter
    [Activity (Label = "Shooter", MainLauncher = true)]
    public class Activity1 : AndroidGameActivity

        protected override void OnCreate (Bundle bundle)
            Game1.Activity = this;
            var g = new Game1();

Right click on the Shooter for XNA or the ShooterMonoAndroidApplication > set up as start project. Press F5 and that will start your emulator or testing device.

Posted: 7/30/2012 9:21:57 AM