4

I've been doing a lot of Windows Phone 7 games development and have started looking into porting my apps and games to iPhone and possibly Android at a later date.

From my understanding solutions such as MonoTouch are not worth the effort, so should I stear clear of such things?

I'm well versed in C++ coding and would like to do that on the iPhone if I can't use C# effectively, especially for performance critical situations which games have a lot of. I don't underestimate the power of C#, just C# on iPhone (and I think that's a fair thing to be afraid of).

Would there be any good reading material I should get into before building up code for iPhone? I'm already downloading x-code but don't know what to do beyond that, I odn't even know how to wrap C++ around objective-c but I feel that would be the best compromise given my situation.

I guess a broader question is how would I handle multiplatform programming? My currnet idea is to build three seperate development frameworks which share the same design principles as each other so porting apps between platforms is straight forward (but would still require re-writing code every time).

Is that a smart way to do it or am I just crazy?

meds
  • 21,699
  • 37
  • 163
  • 314
  • 1
    What makes you think negatively towards monotouch? There are people writing very effective games in c# this way, especially with "unity" etc – Marc Gravell Apr 03 '11 at 09:38
  • Oh I really don't know, it just seems to me that it would be difficult to get C# to run very fast on iPhone considering it has to be compiled down to machine code for iPhone to 'understand'. It was just an assumption that people couldn't write compilers which could get C# to execute as fast on the iPhone as say, WP7, where C# is natively supported. – meds Apr 03 '11 at 09:41
  • 1
    "C# is natively supported"? Interestingly on the iPhone, C# is Ahead Of Time compiled, while on WP7 it is JustInTime compiled... – Stuart Apr 03 '11 at 09:44
  • @Marc Gravell - From what I understand, Unity is a different C# solution - it's not MonoTouch - but it might be another useful solution for @meds to consider. – Stuart Apr 03 '11 at 09:50
  • @Stuart, given C# is a managed language native support is probably more JIT than ahead of time, ahead of time means it has already been compiled to machine code so the platform understands it – meds Apr 03 '11 at 10:14
  • 1
    @meds - Apple have banned JIT - that's why MonoTouch does Ahead Of Time compiling. e.g. see http://stackoverflow.com/questions/1453355/how-monotouch-works – Stuart Apr 03 '11 at 10:16
  • @Stuart thanks for the correction; I deal with it only second hand, via users of libraries of mine... – Marc Gravell Apr 03 '11 at 10:53
  • Check this link also for your decision http://stackoverflow.com/q/5335764/75825 – nemke Apr 03 '11 at 16:08

3 Answers3

7

C# on the iPhone not only works fine, but it works brilliantly. It is compiled AOT that is "Ahead of Time" (normally .NET code is compiled JIT - "Just in Time") down to machine code just like a normal compiler would produce. It's absolutely fast enough for game development and about 100 times easier to use.

I have two XNA games working on iOS and my own crowd-funded iOS port of XNA, which is also coming soon to Android (ExEn). So I can definately confirm that C# on iOS is fine for game development.

Now if you're doing a 3D game, I'd be looking into Unity. The cross-platform XNA solutions are all 2D-only - for the moment anyway. The other option is using OpenGL directly with the bindings in MonoTouch.

Basically you should do everything you possibly can to avoid having to write your game more than once. To that end, C# is an excellent choice.

Andrew Russell
  • 26,924
  • 7
  • 58
  • 104
  • So that would mean I should license monotouch and go about porting my code over? My biggest problemw ith that is I have a third party library (Farseer Physics) which is dependent on XNA, I'm not sure how I would go about moving Farseer over to iOS... Your ExEn project looks nice but doesn't seem to be out yet so not too sure that would help.. – meds Apr 03 '11 at 22:40
  • @meds Yes. You can get (paid) early-access to ExEn at the moment. Or you can use MonoGame (it's not as good as ExEn, but it should be enough to get Farseer to compile). Even if those project didn't exist, the maths types that Farseer needs are fairly straightforward to implement yourself. Once you have the types, Farseer should run pretty much out of the box on MonoTouch. I have not tested Farseer 3. One of my games uses Farseer 2 (a different codebase) - it had a single, admittedly obscure, compile error in it - once fixed it worked fine. – Andrew Russell Apr 04 '11 at 01:25
  • @Andrew Russell, how much am I supposed to pay and where do I pay it? Also how is your vertex buffer support? I understand ExEn is only for 2D (so I assume spritebatch?), one of my games uses orthogographically drawn vertices for 2D angled terrain, would that be ok with ExEn? – meds Apr 04 '11 at 03:44
  • @meds: Currently: email me; or check my website in a day or two and I will have a payment system up. At the moment neither ExEn or MonoGame have working support for the 3D graphics APIs - even if you just use them for 2D drawing. My current recommendation is to use ExEn (or MonoGame) for everything, except: have an alternate path that uses OpenGL in the places where you use the 3D API. – Andrew Russell Apr 04 '11 at 04:16
  • @Andrew Russel, This might be quite a large question but how would I go about with setting up alternative paths to draw vertex buffers? Is there a way to mix ExEn/C# with C++/OpenGL ES? – meds Apr 04 '11 at 04:40
  • @Meds You don't have to use C++. MonoTouch uses OpenTK to provide a C# binding of OpenGL ES (which is what ExEn uses internally). So in your code you'd just wrap your 3D stuff in a `#ifdef`, and provide one set of 3D drawing code for XNA, and one that uses OpenGL. (It is possible to call into C++ code from C# with P/Invoke, but you don't need to.) – Andrew Russell Apr 04 '11 at 05:48
  • @Andrew Russell, So it would effectively be me using MonoTouch OpenGL ES functionality in the place of the XNA stuff I would be using on WP7? How would this interact with Spritebatch? Can I expect the same sort of behaviour between the two since when I start using OpenGL ES I'll end up being outside the umbrella of the XNA wrapper functionality. Would it be safe to assume that the XNA wrapper is not 'cheating' with its spritebatch fucntionality for example (i.e. when I set layerdepth to '1' it actually is drawing at a distance of '1' away from the camera?). – meds Apr 04 '11 at 06:59
  • @meds: That functionality still counts as 3D, so it's not currently supported and that *wouldn't* be a safe assumption. That being said, you do get source-code access and that seems like a pretty easy modification to make. – Andrew Russell Apr 04 '11 at 08:37
  • @Andrew Russell, hmm alright, looks like there's going to be some severe headaches with adding 3D support then.. – meds Apr 04 '11 at 14:03
  • @meds Well, you'd have to write some OpenGL code. But that's still a big step up from rewriting your *entire* game in C++ and OpenGL. – Andrew Russell Apr 04 '11 at 16:10
  • @Andrew Russell oh definitely true, it's just that there are some unknown factors at work here when using direct OpenGL calls along with wrapped XNA functions.. When are you putting up a link for paid ExEn? – meds Apr 04 '11 at 23:20
  • @Andrew Russell, Awesome, will cough up for it once I've figured out and am comfortable with using a mac :) Hope you make the 5k, and the extra $$$ for 3D support too :D – meds Apr 05 '11 at 05:33
3

You don' have to wrap c++ around objective-c. c++ compiles just fine on the iPhone. You can easily develop all your code for multiplatform games in c++. What I don't know is how c++ compiles on wp7, but that's another issue :)

Marko Hlebar
  • 1,973
  • 17
  • 18
  • C++ doesn't compile on iPhone, yes I know, sucks :P haha :D – meds Apr 03 '11 at 09:46
  • @meds read this :) http://stackoverflow.com/questions/270455/is-it-possible-to-program-iphone-in-c – Marko Hlebar Apr 03 '11 at 09:49
  • bah to edit my original comment, I meant C++ doesn't compile on WP7. Gosh, it's 8pm and I'm already nackered/. – meds Apr 03 '11 at 10:13
  • Yep, that really sucks... I wanted to port a game to WP7, but stopped after writing a particle system. It was wasting too much time to rewrite my existing code to C#/XNA :) – Marko Hlebar Apr 03 '11 at 10:53
1

From my understanding solutions such as MonoTouch are not worth the effort

I've just voted to close this on the grounds of it being subjective and argumentative...

... but while it's still open ...

In my experience, MonoTouch offers an excellent solution:

  • if you want to leverage a single code base and existing skills
  • if you want to take advantage of CLR memory management
  • if you can cope with the increased download size
  • if you don't need to link with existing Obj-C libraries (you can link to these in MT, but in my experience it's not always a straight-forward process to do so)
  • if you can budget for the MonoTouch license fee

For XNA in MonoTouch, see http://monogame.codeplex.com/ (latest now on GitHub)


For general iphone getting started advice, try: https://stackoverflow.com/questions/332039/getting-started-with-iphone-development

Community
  • 1
  • 1
Stuart
  • 66,722
  • 7
  • 114
  • 165
  • It was just something I"ve heard, I didn't mean to say it as it were fact, just something I've heard mentioned elsewhere. – meds Apr 03 '11 at 09:46