In the previous screencast I showed how to install and setup HaXe and NME on a Windows 7 machine and compile to Flash and Android. This time I will demonstrate how to install and setup HaXe with NME on a Mac OS X machine and compile an open source project called BunnyMark to the iOS simulator in Xcode.

Note that you can only compile for the iOS on a Mac OS X as the compiler generates an Xcode project that Xcode then compiles.

If you have read my last post then you will know that I am endeavouring to increase my focus on mobile development. This lead to one reader mentioning an API called NME that allows code written in HaXe (very similar to AS3) to cross compile natively to Flash, Android, iOS, webOS, Windows, Mac, Linux, and HTML5 targets.

As the code is natively compiled (c++ for Android and iOS) the performance is perfectly acceptable for physics based games. This is in contrast to Adobe Air’s export to Android and iOS that has a Virtual Machine interpreting the code thereby causing poor performance.

So far I have ported a couple of earlier Box2D tutorials and successfully ran them on my Android phone at a smooth frame rate. I was also able to get it working well with the iOS simulator.

If you are interested in programming with NME then I thought I would post a screencast tutorial to demonstrate how to install and setup HaXe with NME and compile a simple HelloWorld application to Android and Flash.

Box2D Fixed time step
So far, in each tutorial, we have been calling the step function on each frame update with a fixed delta time to apply the physics. This works quite well as we have seen.

However, there is a problem with this approach. While we may be targeting a frame rate of say 60fps, there is no guarantee that it will update that frequently. A user’s computer hardware may cause it to run slower or faster than this, and subsequently, the physics simulation may appear to run either in slow motion or to appear sped up.

So if you are finding this a problem in your game how can we go about fixing this? The answer is to separate the physics update from our game loop so the physics is not dependant on how often the game loop is called. Read more

Continuing our Box2D camera tutorials, we will now look at creating a specific camera, that being the “Platform Camera”. The platform camera is similar to the follow camera, except that the camera will not always necessarily pan the world to keep the target in the centre of the screen. Instead, we will set invisible margins on the sides of the screen and only when the target crosses these boundaries will the camera pan to prevent the target from disappearing off the screen. Read more

In the last tutorial we started work on our BasicCamera for Box2D, where we added functions such as lookAt and panning so we could translate our camera position, as well as helper functions to convert from world to raster coordinates and vice versa.

We will again be revisiting this class. This time, so that we can add zooming capabilities. Read more