Anatomy of a cross-platform iOS/Android app

There hasn’t been a lot of news posted lately, which is just because we’ve been busy making some big changes to the Cricket Audio code; we’ll post more about that when we’re ready, we promise!

In the meantime, though, I thought it was worth spending some time talking about cross-platform game development.  Cricket Audio is tremendously useful even if you’re just targeting one platform, but where it really shines is how easy it makes your audio programming for a cross-platform game targeting both iOS and Android.

I’ve posted briefly before about cross-platform development, but I’ll recap.  On iOS, the usual programming language is Objective-C.  On Android, it’s Java.  If you’re targeting just one platform, that’s fine (and in fact, we provide interfaces to Cricket Audio for both languages).  If you want to write code for both platforms, though, the one common language they can both speak is C++.

Of course, simply having a C++ compiler on both platforms is not enough without cross-platform APIs to actually do something interesting with your C++ code.  For graphics, the obvious choice is OpenGL, which is a C API that is available on both iOS and Android.  For audio, of course, look no further than the Cricket Audio C++ interface.

So how do you actually go about using OpenGL and Cricket Audio to make a cross-platform game?   We’ve put together a simple example in the Cricket Audio distribution; you can download it here.

The cross-platform interface is in src/samples/game/game.h.  There are a handful of functions there for things like initialization, rendering, and dealing with touch interactions; the platform-specific code then just needs to create the appropriate app framework and call these functions to take care of graphics, sound, and game logic.

The game, running on a Nexus S (top) and an iPod Touch (bottom)

The platform-specific code is in src/samples/game/ios and src/samples/game/android.  On iOS, we create an app with a single OpenGL view; on Android, we create an activity with an OpenGL surface, then use JNI to call into the native code.

When you run the game, you’ll see an orange pyramid and some spinning cubes.  (Not the most sophisticated graphics ever, we admit; but hey, we’re audio guys, not graphics guys!)  Drag your finger on the screen to move forward or backward or turn; the object is to poke the orange pyramid into the cubes.


This entry was posted in Android, Audio, Cricket Audio, Game Development, iOS. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *