Archive for the ‘Coding tips’ Category

Hiding the status bar fun

September 19, 2008

One issue a few iPhone game developers like me have run into is that for most games you want to have the status bar hidden. Now theoretically this is quite simple to do, by simply having UIStatusBarHidden ticked in your Info.plist settings.

And in fact, this was working for me, until at some point I made some other modifications to Info.plist and it the status bar suddenly started being shown. Looking around the net, I found other people mentioning the same problem. One solution mentioned was disabling the status-bar with the code:

[application setStatusBarHidden:YES animated:NO];

Now this code does works, but the problem with it is is that until the code is executed, the status bar shows – so your splash screen will come up with the status bar still showing, which is kind of ugly (you can still see this effect in some published apps/games).

The solution to my problem turned out to be that in editing Info.plist I’d somehow switched it from being in XML format to a key=value format file, and in this format the setting just wasn’t working (you can simply check by viewing Info.plist in any plain text viewer/editor). I converted it back to XML format, and voila, it worked again! Hope this helps some developers stuck with the exact same problem 🙂

Getting the sound output ‘right’

September 19, 2008

There’s at least three ways to do sound for the iPhone. The simplest way however – using System Sound Services – is not recommended for games, where you want to be playing multiple, and potentially long, sounds.

So for our needs, we were basically left with a choice between Audio Queue services, which seems to be the generally recommended way to do sound in games, and with using the SoundEngine class from Apple’s CrashLanding example, which uses the Open Audio Library, which also has the potential advantage of supposedly being cross-platform.

I tried both using Audio Queue services and the SoundEngine. It turns out that the Audio Queue services have the advantage that you can at least hear something in the simulator when using. The disadvantage that I found however was that it was tricky to get working nicely, and had some issues I was never able to solve, for example if I played stereo sounds then there were audible audio artifacts whenever I stopped/started them, even though doing everything the same with mono sounds there were no problems, which seemed to indicate the problem was internal.

So I went for using this SoundEngine class. It turns out this is very simple to use and basically just works. In our first release of Fuzzle, we released with this, however we then discovered one problem – by default, it fades out, and stops any existing music playback, when the application starts. Turns out a number of games have this same problem …. the user can always, after application start, double-tap the home key and restart the music, however then the game sounds stop working, and most importantly, some users don’t realize this and complain in reviews!

The fix for this, which is in our next update already, turns out to be the following three lines of code, which should come immediate before the call to SoundEngine_Initialize(…):

    AudioSessionInitialize (NULL,NULL,NULL,NULL);
    UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
        sizeof( sessionCategory ),
        &sessionCategory );

And with this code added, the game seems to co-exist perfectly happily with background music. Of course, if your application/game has its own music etc, then it may make sense to leave the default method of stopping any existing music playback. And once this update has been out, we’ll see if any other problems surface, but at the moment this seems to be the ‘right way’ to handle this 🙂