August 22nd, 2010 § Comments Off on The Sparrow Framework § permalink
When I first started iPhone programming last year, I decided I wanted to stay away from third-party frameworks at first, so I could learn as much of the native environment as possible. My first animation-based project used CALayers, but I later converted it to use OpenGL for better performance.
I am definitely not opposed to using third-party frameworks. When I’m not trying to wring the last bit of performance out of a device, I’d rather deal with higher-level abstractions than directly with OpenGL.
Cocos2D-iPhone is a very popular open source framework for 2D games and graphics applications. It seems very feature-rich, including things like visual effects, particle systems and even integrated physics engines!
But I was immediately drawn to the Sparrow Framework when I first heard about it. It, too, is an open source 2D graphics/game framework for iOS. It has far fewer features than Cocos2D (possibly a boon, depending on your outlook—less code to add to your app) but its main attraction (to me) is that it is modelled after the ActionScript 3 API. For someone like myself who has used Flash for many years, this is a definite plus.
When I was writing the Vampire simulator, I needed to make the vampire sparkle. I figured that this simple animation task would be well suited for my first exploration of the Sparrow framework.
Creating a new Sparrow app is very simple. Just duplicate the “scaffold” folder and rename the Xcode project within. You will have to do a one-time Xcode settings change: adding a SPARROW_SRC folder reference to point to where the Sparrow source files are on your hard drive.
The documentation that is available for Sparrow is minimal but very, very clearly written. Also, the source code is easy to follow. If you have any background with the ActionScript 3 class library, the learning curve is practically zero. I was shocked at how quickly I was making things happen with it.
Here’s a simple example from the vampire app. This snippet places the image “vampire.png” at the centre of the screen:
Responding to events (touch events, or timing) will be familiar to you if you’ve used ActionScript (or JavaScript, for that matter), using the addEventListener method:
This will cause the onEnterFrame: method on self to be called on every frame of the animation.
Refugees from Flash should note: while Sparrow is modelled after the ActionScript 3 libraries, it is only a small, small subset of it. For example, it does not include any of drawing API (on the other hand, if you want to do any custom drawing, you can subclass SPDisplayObject and draw with OpenGL directly).
I definitely plan to use Sparrow for whatever my next game project might be. I’ll likely have more to say about it then. I’ll be interested to see how performance holds up if a lot of elements are flying around the screen.
iOS 4 added a lot to AVFoundation, including classes and APIs that give you much more control over the iPhone camera. One of the things you can now do with the camera is read the video frame data in real time.
In this post, I’ve created a simple demo that simulates a Twilight-style vampire. In the Twilight series, vampires aren’t hurt by daylight; instead, they sparkle. Yes, sparkle.
The app detects the amount of light shining on the phone by doing very simple image analysis of the incoming video frames from the camera. The brighter the image seen by the camera, the more sparkles it draws on the vampire.
August 8th, 2010 § Comments Off on iDevBlogADay § permalink
Like many people with barely-updated blogs, I want to blog more often. I’m not much of a writer but that can only change with practice, right? Plus, I’m a big believer in community and the sharing of knowledge, and I wanted to contribute to that more. But where would I find the writing discipline?
I’ve also been a fan of personal writing challenges for some time. For example, I’ve participated in National Novel Writing Month (NaNoWriMo) for many years, where the goal is to write a 50,000-word novel in 30 days (in November). The concrete and public goal, combined with the camaraderie of the others involved, makes for a fun creative exercise and certainly helps with motivation.
When I heard about #iDevBlogADay on Twitter, I had to know more about it. It apparently all started when independent iPhone developer @MysteryCoconut wanted the impetus to blog more often, a sentiment that I can definitely relate to myself. What began as an offhand tweet has ballooned into what could become a bonafide movement.
Here’s how it works: Each day of the week is assigned to two indie iOS developers. They must post a blog post on their assigned day. If they miss a day, they’re out and sent to the end of the current waiting list. The next blogger in the waiting list now takes that person’s place.
What’s cool about this is that this kind of motivation helps everyone. The explosion of shared knowledge and inspiration pouring forth from these blogs has been pretty awesome.
It’s now my turn to take a spot on the Sunday roster. I have to admit I’m intimidated, as the quality of the blog posts has been high! I can only hope I can live up to the standards that have been set. (And I apologize for the “fluffy” nature of this post—I had a “crunchier” blog idea that I had apparently been sitting on for far too long, since it was rendered obsolete by recent versions of the iPhone OS. That’ll teach me!)
Hats off to MysteryCoconut for starting a fun “game” that helps and fosters the entire iDevelopment community :)
Where Am I?
You are currently browsing entries tagged with idevblogaday at
bunnyhero dev.
Asides
I have restyled my blog again, using Andrea Mignolo's beautiful Oulipo theme. Andrea (aka pnts) is a very talented and smart web designer and developer now based in Vancouver, BC New York, NY.