Sparrow 2.1
Daniel Sperl on July 7, 2014I’ll jump right to the most important message of this blog post: this Sparrow update is huge. In fact, I considered calling this “3.0” because it’s lightyears ahead of any previous Sparrow version! But one thing after the other.
The last year hasn’t been easy on our little bird. Sparrow 2.0 launched proudly and with a lot of confidence. It had a modern architecture and great potential, so what could possibly go wrong?
Sprite Kit
Then, Apple launched Sprite Kit: a framework with the same target audience as Sparrow, with a nice Xcode integration, directly supported by Apple. Our little blue fledgling had one hell of an identity crisis, I can tell you. It had been officially sherlocked!
But what does a real bird do if it flies into one of those damn-hard-to-see glass windows? Exactly: it pats the dust off its feathers, picks a new flight route and launches again. Never give up, never surrender!
Sparrow will always have one great advantage: it’s Open Source! Tinker with it, modify it, play with it — and yes, fix it! It’s all in your power. If you run into a problem with Sprite Kit, good luck with Apple fixing it. If they mind at all, the fix will only be in the next iOS version, so effectively you just have to live with the bug. Not so with Sparrow!
In short, there’s no reason to give up! On the contrary: with this release, Sparrow is more powerful than ever. So without further ado: follow me along a quick tour through Sparrow 2.1!
Back to MRC
This time, Sparrow is not a “Daniel-only” project. In fact, most of the code of this version has been created by Robert Carone, an amazing California-based developer who miraculously knocked on the door a few months ago, telling me that he’d made Sparrow about 250% faster. How is that possible, you ask?
Well, by converting Sparrow back to MRC! I didn’t believe it at first; after all, ARC is considered to yield roughly the same performance as MRC, if not more. That’s what Apple always told us, right?
Well, not so for Sparrow. Maybe it’s because Sparrow is a pure Objective-C rendering framework (many others use C/C++ internally), or that I’m doing something that doesn’t work well with ARC; I don’t know. We had a long discussion about this in the Apple Developer Forums, without any meaningful results. Fact is, ARC just did not cut it for Sparrow. 250% performance gain — that’s something that can’t possibly be ignored. So Sparrow 2.1 is back to MRC, and it works beautifully.
Don’t worry: this doesn’t mean that you can’t use ARC in your games. You can, and in fact I’m still recommending it! It will spare you a lot of trouble and will shorten your development time. Let Sparrow deal with the performance-critical stuff.
Performance Boost
Apparently, after this success, Robert tasted blood. He now looked at other parts of the framework and found several really smart optimizations. All in all, this Sparrow version is about three times as fast as the previous release. Yes, you read right! Three hundred percent. That must be the biggest speed-up since I plugged the first Voodoo card in my Pentium back in ‘98!
Fragment Filters
Many of the other features are things that were long overdue and were literally just waiting to be ported over from Starling.
The most notable new feature: filters! Any Flash or Starling developer will love them, because they make it really easy to add specific effects to your display objects. Out of the box, Sparrow contains the following filters:
- Blur
- Drop Shadow
- Glow
- Color Transformations
- Displacement Mapping
However, people who are proficient with OpenGL will be able to add their own filters easily. Just extend the new “SPFragmentFilter” class and add your custom GL shader code. Eat this, Sprite Kit! ;-)
Here’s how those filters look like in action:
To use a filter, simply assign it to the new “filter” property that’s part of every display object.
object.filter = [SPBlurFilter blurFilterWithBlur:2.0f];
Clipping
You can now easily add a rectangular mask to any sprite. The new “clipRect” property can be set to an arbitrary rectangle; only the contents within this rectangle will be drawn. The nice thing about this feature is that it’s very cheap: it comes at the discount price of just one additional draw call!
To see it in action, you can navigate to the “Clipping” scene in the Sparrow Demo.
Swift
Since this year’s WWDC, there’s another cool new bird in town: Swift! With its concise syntax and impressive performance, it’s clear that this new programming language will quickly outgrow Objective-C in popularity among iOS developers.
Sparrow developers can make use of it right away: the two birds play nicely together! The following sample code shows you how natural it feels to use Sparrow from Swift:
To get up and running quickly, you can use the new Swift-variants of the Scaffold and Barebone projects that come with Sparrow. To find out how to add Swift-code to your existing projects, take a look at this tutorial in the Sparrow Wiki.
Sparrow dot Framework
Previously, the only way to use Sparrow was by adding it as sub-project to your game, requiring a somewhat complicated “source tree variable” set-up.
You can still do that (and that approach has several advantages), but it’s not your only option now. If you want to add Sparrow to an existing project, you can now simply drag & drop the new pre-compiled “Sparrow.framework” module into your project — identical to how you’re using Apple’s original frameworks. It doesn’t get any easier than that!
Besides, the new version will soon be part of CocoaPods, for those who use this excellent dependency manager for their project setup.
I’m just getting started!
That’s just the tip of the iceberg, but I had to keep the length of this post within reasonable bounds!
- A new entry point for upcoming physics libraries (“physicsBody”)
- Full 64 bit compatibility
- SPPoolObject is now thread-safe
- Complete rewrite of texture loading, thus getting rid of Apple’s buggy GLKTextureLoader
- Support for rotated atlas textures
- Automatic texture caching
- Lots of bugfixes
- Pixel-level masking via this extension
For the complete list of changes, check out the changelog on GitHub. There are lots of new utility methods and useful helpers, too, so be sure to check it out!
Wrapping it all up
I can only repeat how thankful I am for Robert’s support with this release. Actually, the majority of these changes were implemented by him, and he did an amazing job on all of them!
A big thanks goes also to the community: your feedback and encouragement is what is keeping Sparrow airborne! Without your valuable comments and bug reports, this release would never have made it.
Please give the new version a try and tell me how you like it! Don’t forget to leave a comment below — I’m looking forward to your feedback!