Followers 0

# Unity Port XNA to iOS step-by-step (using MonoGame)

## 10 posts in this topic

Hey everyone,

So I have an XNA 4.0 windows game in VS2010 running on my Windows PC (windows 7).

The game itself isn't finished yet, but before I continue work on it I'd like to try to get it running on my iPad, so that I suss out the porting procedure and feel confident about continuing to use XNA. The primary platforms I'd like this game to go on would be on Windows (and possibly Mac) and iOS.

I know that monogame is the way to go with porting XNA to iOS, but I'm finding it difficult finding step by step walkthroughs as to how to actually do this.

This is what I currently have:

A windows 7 PC

Visual Studio 2010

My XNA 4.0 game project on windows 7

A Macbook

MonoDevelop (it was installed as part of the Unity 4.0 install)

An iOS developer account

Latest XCode

Can anyone point me to any tutorials or guides as to how I can, from here, get my game ported over to iOS? Any comprehensive help and tips along with them would be much appreciated.

Thanks so much.

1

##### Share on other sites

Well... now time for the bad news...

You also need a copy of Xamarin for iOS ( previously known as MonoTouch ).

Now for the worser bad news...

Actually, no longer! If you use their brand-new Xamarin Studio package, you can release to Android, iOS, and Mac OS X for free. The free version is really only usable for smaller apps that don't require P/Invoke (its not supported) and the version that does support P/Invoke is $299 (for everything). Its not perfect, but its a good starting point. As far as XNA to MonoGame is concern, it should be pretty straight forward if you are only of Windows. When you get into Mac and Linux it does become slightly more complicated. I've never really worked with XNA or MonoGame, but people who I know have (and made the switch) say it isn't had to move. Still, my first move would be to switch from XNA to MonoGame in Windows first and then switch from Windows to Mac OS X or Linux. 0 #### Share this post ##### Link to post ##### Share on other sites Well... now time for the bad news... You also need a copy of Xamarin for iOS ( previously known as MonoTouch ). Now for the worser bad news... It has a 299$ price tag.  There is however a 30 day full functioning trial I believe.

Actually, no longer! If you use their brand-new Xamarin Studio package, you can release to Android, iOS, and Mac OS X for free. The free version is really only usable for smaller apps that don't require P/Invoke (its not supported) and the version that does support P/Invoke is \$299 (for everything). Its not perfect, but its a good starting point.

As far as XNA to MonoGame is concern, it should be pretty straight forward if you are only of Windows. When you get into Mac and Linux it does become slightly more complicated. I've never really worked with XNA or MonoGame, but people who I know have (and made the switch) say it isn't had to move. Still, my first move would be to switch from XNA to MonoGame in Windows first and then switch from Windows to Mac OS X or Linux.

The pInvoke limitation is worse than you think...  Your code may not require pInvoke, but MonoGame does ( that's how it calls to OpenGL ).  I may be wrong, but im 90% certain the "free" version doesn't work with MonoGame.

1

##### Share on other sites

The pInvoke limitation is worse than you think...  Your code may not require pInvoke, but MonoGame does ( that's how it calls to OpenGL ).  I may be wrong, but im 90% certain the "free" version doesn't work with MonoGame.

Well MonoGame uses OpenTK for the OpenGL/ES backends. I checked the source code and it uses System.Runtime.InteropServices not DllImport or any of the other P/Invoke methods (although I don't know what InteropServices does in the backend).

EDIT: Information in this post is completely wrong and invalid.

Edited by Josh Vega
-1

##### Share on other sites

Well MonoGame uses OpenTK for the OpenGL/ES backends. I checked the source code and it uses System.Runtime.InteropServices not DllImport or any of the other P/Invoke methods (although I don't know what InteropServices does in the backend).

I think you misunderstand what p/invoke means.

p/invoke is a shorthand for saying it uses InteropServices to perform automatic marshalling to and from the platform's libraries rather than using the .net method.

The source code you linked to has about 600 lines of this:

[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glDrawArrays", ExactSpelling = true)]
internal extern static void DrawArrays(OpenTK.Graphics.ES20.BeginMode mode, Int32 first, Int32 count);
[System.Security.SuppressUnmanagedCodeSecurity()]
[System.Runtime.InteropServices.DllImport(GL.Library, EntryPoint = "glDrawElements", ExactSpelling = true)]
internal extern static void DrawElements(OpenTK.Graphics.ES20.BeginMode mode, Int32 count, OpenTK.Graphics.ES20.DrawElementsType type, IntPtr indices);

That is a textbook example of p/invoke.

You wrote it does not use DllImport, but every single one of those entries is marked as DllImport.  Every single function is marked with "System.Runtime.InteropServices.DllImport".

That is what Serapth was pointing out.  It uses p/invoke all over the place, which your source code link confirmed rather than denied.

This is one reason I personally dislike the "free" libraries that have requirements of paid libraries.  They are generally less free than they advertise.

Edited by frob
0

##### Share on other sites

Woah!

I don't even know how I missed that. I know that from prior experience that InteropServices is a P/Invoke method. I must have have gotten the question confused with another C# question I was emailed by a friend. Its been a busy day for me.

1

##### Share on other sites

@SeraPath and @Josh Vega: The MonoGame team is working with Xamarin, to have their assemblies white listed, so they can be used with the Free version.

No ETA yet, but it is coming.

@dechorus, I would suggest posting any questions you have in the monogame.codeplex.com discussion forums.

D.

0

##### Share on other sites

@SeraPath and @Josh Vega: The MonoGame team is working with Xamarin, to have their assemblies white listed, so they can be used with the Free version.

No ETA yet, but it is coming.

Now that is an excellent news ! Do I understand it correctly that when these assemblies are whitelisted, one will be able to use the free version of Xamarin, then ?

To be more specific, if I am not using any other assemblies (other than .NET and XNA), I read it that I actually am not doing any other PInvoke, correct ?

Or will only XNA replacements will be whitelisted, but not the .NET ones [for the free version] ?

0

##### Share on other sites

Unfortunately the free version of Xamarin also has a limited app size. I forget the exact size (it's hard to find on their website), but it's very tiny (I think 32KB). The default XNA project already exceeds that size because of the icon. You can shrink the icon, but any not-completely-trival game will exceed that size with just compiled code.

0

##### Share on other sites

32 KBs, as in, half the RAM of an 8-bit Atari 800 XL, from an era almost half a century ago ?

"But -hey- it's free !"

You gotta admit though, that's one great way how to piss potential customers.

I bet that must have been an idea of some CTO. Those are usually the ones displaced / torn out from the reality the most...

I sure would like the stuff they're smoking. Must be of top-most Columbian quality

0

## Create an account

Register a new account

Followers 0

• ### Similar Content

• By NA-45
I'm currently working on Metroidvania style game that I was inspired to start by Hollow Knight and Beksiński's art.

It's built in Unity using C# and has quite a bit done already.  I'm handling the programming myself and have a working model (besides combat which is a WIP) that can be expanded greatly depending on where we decide to take the project.  You can see the current test area here: https://streamable.com/mp5o8  Since I'm not artistically gifted, its all rectangles but can easily be skinned once we've desired on designs.
I have professional experience using Unity and C# working on both a released game and a prototype as well as having extensive Java knowledge.  I also dabble in Python with a little bit of C++.
I have worked on and completed many projects before, the most recent being a 2D stick fighting game written ground up in Java Swing (don't ask why): https://www.youtube.com/watch?v=V4Bkoyp_f0o
I'm looking for a 2D artist (potentially more than one) to create concept and game art and a designer/writer who can help flesh out the story as well as map out and create challenging and eye catching areas.  I can handle most if not all of the programming side of things though if there is anyone who is extremely passionate about this sort of thing, I'd consider splitting the load.
The end goal is a completed game that can be sold however profit isn't really a concern to me as it's mostly a labor of love from my part.  Any profits would be split between team members however that's pretty far off so don't make that a reason to join.
______________________________
The story I have in mind is something like this:
A man wakes up in a chasm that stretches seemingly endlessly in both directions lined with enormous statues.

He discovers a temple with text above a closed gate that tells of the failed kingdom that lies below.  After finding a way around this, he drops down into the subterranean kingdom.  Adventuring through the labrynth below, he comes across different cities in which the residents succumbed to different sins such as Greed, Wrath, etc.  Each city tells a story of how its fixation on something lead to their demise leading up to a fight with the personification of their mistake.
______________________________
An very rough idea for Waterways, a potential area:
- To enter you must be wearing a pair of glasses that you find somewhere earlier in the ruins.  There are similar glasses found in every home.  Everything appears incredibly beautiful however something seems wrong.  After triggering some event, the glasses break and it's revealed that the glasses are made of some sort of stone that makes everything appear differently.  The city is in ruins and absolutely disgusting as everything was neglected.
- The only thing that remains intact is in the center of the city, an incredible statue of a goddess holding up a large sphere of the same material that was used for the glass.  You slowly learn the story behind the statue: the goddess came from the sea that the city lies on and brought prosperity to them.
- After opening up the the temple of the goddess that lies right on the edge of the waters, a giant sheet of the glass covers an opening in the back of the temple that reveals the goddess behind it.  You shatter the glass and it becomes apparent that the goddess is actually a disgusting creature half beached and mostly immobile that appears to secrete the material that makes up the glass. Fight ensues.
______________________________
The combat is pretty up in the air and part of the reason I need a designer to bounce ideas off of but I think it will be something like this:
- 4 orbs equipped at a time
- 2 orbs selected at a time
- Pressing the cast button will cast a spell determined by the 2 orbs that are selected
- Spells cost mana however you can use spells with 0 mana and it will cost health instead
- These spells in addition to being useful for combat, are the Metroidvania "gating" metchanic.  For instance, one of the conceptualized spells is a water orb + water orb to create a ice pillar that can be either used to block projectiles/enemy paths or to jump on to reach high areas
______________________________
If you're interested or have any questions, contact me through discord.  My id is NA-45#3692.

• My game (built on the Unity platform, making use of EZ GUI) requires players to log into Facebook. However, when the player is using a language other than English on Facebook, I'm unable to display the localized Username (which is the same as the FB Username) within the game. Any ideas on how this can be tackled?
PS: Detecting the OS language doesn't really help here because, for all you know, the player might be using one language for the OS, but another one for their Facebook, so....
TIA!
• By NajeNDa
Hi there,
I am a game programmer (C#/C++) who is looking for a project to join. I am computer science engineer plus Master Degree in Game Development, currently working in one the most renown mobile games company (2 years academic experience, 1 year working experience).
I have developed several prototypes or even games almost ready to release, but I always lack of artists, so I am looking for a project already set up or few artist to begin working in something.
My preferences are:
Unity or Unreal Engine 4 based project (UE4 prefered) PC/Console game prefered but mobile is acceptable Not interested in VR Serious team with almost all the roles filled or pretending to be filled 3D project prefered over Sprites Guaranteed 7 work hours per week, Crunch 20 work hours per week  European team (if timezone is not a problem for you, so it is not for me) I am not looking for any kind of money income from games neither the team, I want to do this as a hobby and a way to improve my skills.
Cheers

• SumiKen : Ink Blade Samurai is released! Download and leave a review to help support the game!