XNA Game to iOS (iPhone, iPad)

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

This article uses a sample 2D shooter game with MonoGame on iOS. The shooter can be found at the MonoGame starter kits page.

Prerequisites

  • MonoTouch
  • MonoDevelop
  • MonoGame (assemblies included in download)

Folder structure

Lib has all the referred assemblies. Call you game folder ShooterMT for MonoTouch. To the right, add a folder called Shooter. This contains the XNA version of the game and its content folder. Here is an image of the folder structure:

2012-04-24_09-00-57

Project

In MonoDevelop, create a new iOS blank universal project:

2012-04-24_08-58-14

In your program.cs file, add this code (if it doesn’t already exist):

using MonoTouch.Foundation;
using MonoTouch.UIKit;

using Microsoft.Xna.Framework;

namespace MonoGame.Samples.Storage
{
    [Register ("AppDelegate")]
    class Program : UIApplicationDelegate 
    {
        private Game1 game;

        public override void FinishedLaunching (UIApplication app)
        {
            // Fun begins..
            game = new Game1();
            game.Run();
        }

        static void Main (string [] args)
        {
            UIApplication.Main (args,null,"AppDelegate");
        }
    }
}

NOTE: Do not create a MacOS project. Otherwise, it won’t go onto the phones.

References

Reference Mono.Framework.iOS.dll and Lindgren.Networking.dll.

2012-04-24_08-59-48

These are included in the lib folder of the download.

NOTE: Do not reference Mono.Framework.MacOS.dll. Although it might work, it will cause several technical issues with your application.

Content

Create a folder called Content in the root directory of your application. Right click the folder and select add > add files from folder.

Go to the bin/Windows Phone/Debug/Content folder and open.

Click include all to choose all the XNB files.

You’ll be asked to link the files, so select the third option:

2012-04-24_09-03-22

If you have folders, you’ll need to create them under your content directory and link the files.

In your iOS project, right click your linked files. Select Build Action > Content. and under Quick Properties, select Copy to Output Directory:

2012-04-24_09-04-32

This will copy these files to the Content directory of the deployment folder.

Files

Similar to content, go to the root directory of your Windows XNA application. Link the files, which you did in the Content area above this paragraph.

2012-04-24_09-17-26

Some code won’t work in iOS. You can surround it with conditional statements like #if windows_phone, so your project will build.

To change the orientation of the phone, go to Hardware > Rotate Right. Here is the final result:

2012-04-24_09-15-04

Posted: 9/24/2012 6:26:59 AM