Sparrow 1.0 released!

Daniel Sperl on October 24, 2010

If you have been worrying because there was no new blog entry for more than 3 weeks - then worry no more: we’ve just been busy finishing the latest Sparrow version.

You read the title correctly: in a step so bold that it took even ourselves by surprise, we stamped the poor small bird with a big, heavy “1.0” version number! ;-)

I know it’s not common for an open source project to reach that version so quickly, but we think that our small bird has earned it. Sparrow now has all the must-have features that an iPhone game engine needs, it has been used in a lot of games that are available in the App Store and is supported by a growing community. Besides, we always intended to keep it lightweight and flexible - that goal is reached, so we think “1.0” is appropriate. And most importantly: a software project can never be finished anyway, so why even try to reflect that in the version number?

Anyway, I guess what you really care about is a list of new features and changes in this new version. Where should I begin?

Support for PVRTC-textures

All current iOS devices support a texture format called “PVRTC” (PowerVR texture compression). This is a special, compressed file format for images. The advantage of this format is that the graphics chip can use it directly, in its compressed form. In other words: you save quite a lot of graphics memory if you use it. These textures can now be used from within Sparrow. Load them just like before; Sparrow will figure out the format and lets you use it just like any other texture.

SPImage *image = [SPImage imageWithContentsOfFile:@"texture.pvr"];

It’s not recommended for all textures, though. The compression works best in photos and other natural structures; in line-art images, the compression can lead to noticeable artifacts. So I recommend you use it only for selected images, e.g. in movie clips, where it is necessary to save texture memory. Expect a detailed blog post about how to use this format soon!

Drawing API

Finally, you can create custom graphics directly from within Sparrow. However, we didn’t reinvent the wheel here! The iPhone SDK already contains a powerful graphics API called Core Graphics. I think we found a very elegant and simple way to use that API in Sparrow. For that, Sparrow makes, for the first time, use of Objective C’s new blocks feature. If you have not heard of them, don’t worry: they are very easy to use. Think of a block as a function you can define inline - AS3 developers are using them all the time.

Here’s a sample of how to create a custom texture with Core Graphics in Sparrow:

SPTexture *customTexture = [[SPTexture alloc] 
    initWithWidth:256 height:128 
    draw:^(CGContextRef context)
        // draw a string
        CGContextSetGrayFillColor(context, 1.0f, 1.0f);
        NSString *string = @"Hello Core Graphics";
        [string drawAtPoint:CGPointMake(20.0f, 20.0f)
                 withFont:[UIFont fontWithName:@"Arial" size:25]];

The thing starting with the caret (^) is the block. Place your drawing code in the block and it will appear on your texture later. If you haven’t worked with Core Graphics before, there are numerous resources on the web that describe how to use them, and chances are high that you will find a blog entry about this topic here on this domain in the future. ;-)

Compiled Sprites

Performance-junkies will be happy about the new class “SPCompiledSprite”. As the name suggests, the class works just like “SPSprite” - you can add other display objects to it, other sprites, etc. However, there’s one new method: “compile”.

Whenever you call that method (or automatically on rendering if you did not call it manually), the class will optimize the rendering of its children so that the number of OpenGL calls that have to be executed is minimal. That means that everything will be rendered extremely fast. And I mean it - you can expect even complex objects to render as fast as if it was just a single SPImage.

Of course, this comes at a price: once compiled, you will not be able to see any changes you make to the children. You can still move the sprite, scale it, rotate it, etc. - but not its children. If you make any changes to its children, you have to call ‘compile’ again to see them. Thus, it’s primarily intended for static geometry that does not (or rarely) change. Internally, Sparrow makes use of this feature when rendering bitmap fonts.

Other changes

These are for sure the most important changes, but there is of course much more:

  • The texture atlas now contains the method “texturesStartingWith:”, which gives you an alphabetically sorted list of textures. Use this in combination with SPMovieClip’s new “initWithFrames:fps:” method that takes all frames of the clip at once. Thus, creating a movie-clip is now a one-liner.
  • A frequent request in the forum was to give SPDisplayObjects a “name” property as a simple means to identify them. That property is available now, supported by the new method “childByName:” of SPDisplayObjectContainer.
  • SPTextField now contains the new property “textBounds” which tells you exactly where the text appears.
  • SPPoint contains the new methods “scaleBy:” and “interpolateFromPoint:toPoint:”
  • The texture utilities were optimized for sharper output (you can skip the “sharpen” flag now in most cases).
  • The scaffold project was modified so that it is extremely easy to create an iPad application: all you have to do now is change the “Targeted Device Family” in the build settings to “iPad”.
  • Several bug fixes that were found with the help of all the hard-working forum users - thanks for your help, guys!

That’s it

Hopefully, we picked the right features for this version so that anybody has found something to enjoy! If you encounter any problems, don’t hesitate to tell us so.

Good luck with your projects! We are looking forward to adding your latest Sparrow-powered games to the In Action page!