Box2D.XNA and XNATouch

Mar 30, 2010 at 9:59 AM
Hi, My company wants to port a Flash game made with Box2D to the iPhone and I am evaluating our various options. We have some ability in .Net and XNA and would very much prefer to use this on the iPhone if possible. It seems that XNATouch will allow this. My question is if Box2D.XNA can be used on the iPhone in conjunction with XNATouch? Thanks, Ed
Mar 30, 2010 at 3:49 PM

I haven't tried it, but it should be possible.  The only dependency it has on XNA is with a couple of the math types.  Assuming XNATouch has equivalents it should be a simple matter of recompiling box2d.xna against the xnatouch reference.

Apr 4, 2010 at 2:27 PM

After a bit of copying and pasting of the Box2D.XNA files into a MonoDevelop project I'm happy to say that it did compile against XNATouch.

I started trying to port the pulleys test and ran into an issue. In /Framework/Render.cs there are references to VertexPositionColor. This class doesn't seem to have been implemented in XNATouch.

I think the debugDraw rendering part of this is going to be the clincher. I'm afraid that I've hit the upper reaches of my ability here and will have to rely on other cleverer folks to implement some kind of OpenGL wrapper. 

Unless you think it's possible to use box2D without necessarily needing debugDraw?

Apr 4, 2010 at 4:24 PM
Edited Apr 4, 2010 at 4:25 PM

Most games don't use debugDraw.  It's mostly just for the test bed.

Here is how we do it in Wayne the Brain:

  • Create some sort of "Entity" class that represents your game objects
  • Each Entity has a sprite (can be drawn with SpriteBatch)
  • Each Entity has a Box2D Body
  • Every frame set the sprites position/rotation equal to the Body's position/rotation
  • Dont forget to scale everything such that your physics is in meters/seconds/etc
  • Dont forget to turn down the iteration count on World.Step until it runs good on the iPhone (slow processor).
Apr 4, 2010 at 4:49 PM

That's brilliant. Many thanks :-)

Apr 10, 2010 at 11:35 PM

If I was using the iPhone as a platform I would stick with C++. It's quite a bit faster on such a limited device.

Apr 11, 2010 at 12:07 PM
Looks like Apple's new TOS has rendered this academic now anyway..! Yeah, been looking into using C++ (prefer that to Objective-C). Feeling slightly defeatist about my prospects of realistically making this now TBH not having any experience in C++.
Apr 13, 2010 at 12:43 AM

If your well versed in C# then C++ shouldn't be to difficult. Just spend as much time learning memory management as that is the biggest difference. It's also the reason C++ can have a significant performance advantage on limited devices.