Simple Clipped Image for Sparrow Framework

I’m currently playing around with the rather fine iOS game engine, Sparrow Framework.

I had been aware of it for a while, but hadn’t really got my hands dirty using it. However I’ve recently resolved to work on a few side projects with Dave Thomson who waxed lyrical about it’s ease of use, so I decided to learn a bit more about it.

It’s great. No, really, it is. It’s fairly lightweight, but quite powerful - it uses a display model similar to Flash so anyone who has coded in AS3 will immediately feel at home. I’m looking forward to mastering it, and I suspect I’ll be writing a few posts about using it in the games I’m working on.

However, the lightweightness does mean that sometimes simple features you want to use aren’t there. That’s not a problem though - it has a small but vibrant developer community, and the main website encourages people to add extensions to it. These are essentially classes or simple modifications posted as gists, or sometimes provided as full github repositories, which are all linked to from the extensions section in the Sparrow wiki. You just grab the files and add them to your own project.

So, here is my first extension:

It’s a simple extension to the SPImage class so that you can display only a sub-region of the image texture associated with the SPImage. If you’ve used Flash, you can think of it as a rectangular mask for the image data. The main difference is that as you move the mask from 0,0 in the SPImage, the remaining image data is drawn starting at the current location of the SPImage object on the screen. That probably makes no sense, but if you play with it, you’ll see what I mean. There’s a reasonable chance that behaviour will sufficiently annoy me in the near future that I’ll fix it.

For an example on how to use it, clone or browse the project repository and have a look in TestClasses/game.m.