Sparrow 0.8 has landed!

Daniel Sperl on June 5, 2010

Finally, the download to Sparrow v0.8 is available. Thanks for your patience, everybody!

I will use this post to describe the most important changes since the last release. However, I also recommend that you have a look at the updated demo project (which is part of the download) to see those features in action.

Audio Support

By far the most highly anticipated feature of this new release is, of course, support for hassle-free audio. I think we found a nice, easy-to-use solution to this. If you’re in a hurry, this one-liner will play audio in any format known to the iPhone:

[[SPSound soundWithContentsOfFile:@"sound.aif"] play]; 

(Don’t worry, the auto release pool won’t touch this sound until it’s done playing.) Of course, this is not all of it. In normal circumstances, you will use the following two classes to add sound to your game:

  • SPSound
  • SPSoundChannel

These two classes act in analogy to the ‘SPTexture’ and ‘SPImage’ classes. ‘SPSound’ contains the data, and ‘SPSoundChannel’ controls its playback. So, if you need a sound multiple times, the ‘SPSound’ will be in memory just once, while several ‘SPSoundChannel’s will play it back multiple times. Here is a real-life example:

SPSound *sound = [SPSound soundWithContentsOfFile:@"sound.caf"];
SPSoundChannel *channel = [sound createChannel];

[channel play];
[channel pause];
[channel stop];
[channel addEventListener:@selector(onSoundCompleted:) 

That should speak for itself. Behind the scenes, the SPSound class will choose the appropriate technology for playback: uncompressed files will use OpenAL, compressed sound will be handled by Apple’s AVAudioPlayer. You don’t have to care. Besides, your sounds will automatically be paused when the application is disrupted (e.g. by a phone call), and will continue playback where they stopped.

In the next blog post, we will show you which audio formats should be used for best performance, and how you can easily convert your files into these formats.

"Demo App: Sound"


Sparrow now contains a very lightweight movie class: SPMovieClip. You can imagine this class as an SPImage with changing textures. (As it extends SPImage, it is really just that.)

// load frames from atlas
SPTextureAtlas *atlas = [SPTextureAtlas
SPTexture *texture0 = [atlas textureByName:@"frame0"];
SPTexture *texture1 = [atlas textureByName:@"frame1"];
SPTexture *texture2 = [atlas textureByName:@"frame2"];

// create movie clip
SPMovieClip *movie = [[SPMovieClip alloc] 
                      initWithFrame:frame0 fps:10];
[movie addFrame:texture1];
[movie addFrame:texture2];

// add sounds to certain frames
SPSound *sound = [SPSound soundWithContentsOfFile:@"sound.caf"];
[movie setSound:[sound createChannel] atIndex:0];

// important: add clip to juggler
[self.stage.juggler add:movie]

This will display all the frames in sequence with the specified frame rate. There is more to this class - a detailed description will be part of one of our next blog posts.

"Demo App: Sound"

New Transition functions

Your tweens can now animate stuff in all important transition styles, like “bounce” or “elastic”.

"Sparrow Transitions"

Other Changes

Here are a few other minor changes:

  • SPJuggler now supports the handy method ‘removeTweensWithTarget:’
  • SPDisplayObjectContainer now supports the method ‘removeAllChildren’
  • The rotation property has changed a little bit: angles are now clamped between -180 and +180 degrees (before, it was 0-360 degrees). This should make most common rotation tweens easier.
  • Flickering at application start was removed
  • The stage property is now accessible in the REMOVED_FROM_STAGE event
  • Many other bugfixes and some performance improvements

Feedback wanted!

We did our best to test the stability of the new release - but, of course, we might have missed something. So if you have any problems with the new release, don’t hesitate to post it in the forum, and we will do our best to help you out.

I hope you like the new feathers of Sparrow 0.8! Have fun!

P.S.: One more thing - you will have to add the following frameworks to your game project, as they are needed for the audio classes: “OpenAL.framework”, “AVFoundation.framework” and “AudioToolbox.framework”.