Posts tagged iOS

We made another nifty little extension!

UIView+BlurFade is an Objective-C category lets you take any UIView and make it blurry and greyscale. This is super useful for when you want to make a view look disabled, and looks really pretty to boot!

This category uses Core Image to perform the blurring and grey-scaling. Because you can't apply CIFilters to views on iOS, it actually cheats a little bit - instead of gradually blurring the view over time, it blurs it once, stores it in an image, and then fades that image over your original content.

To use this category, just drop the two files into your project and #import them. Then, when you want to make your view go blurry and faded out, you just do this:

To remove the blur effect, you call its counterpart:

We hope you find UIView+BlurFade useful! If you have any comments, either create an issue on GitHub, or shoot us an email!

Using Gesture Recognizers with Cocos2D and CCNode + SFGestureRecognizer

One of the most interesting and useful features that iOS includes is the gesture recogniser. Gesture recognisers are objects that are attached to views, and look for specific patterns of touches. When a gesture recogniser notices that the user has interacted in the way that it’s looking for, it notifies a delegate.

Prior to gesture recognisers, handling complex gestures like pinching or rotation was a lot harder than it had to be. Time was, developers had to manually track the touches involved in a gesture, and measure how they were moving over time; nowadays, we just do this:

And then have a method that gets run when the user interacts with the view with a rotation gesture:

Gesture recognisers are one of those APIs that are completely obvious once you think about them, and solve a potentially tricky problem very cleanly. However, gesture recognisers have to work within the bounds of how views in iOS work, which can have some interesting consequences for using them in games.

To put it briefly: how can we use gesture recognisers in OpenGL-based games?

Here’s the problem: gesture recognisers work by being attached to views; when a touch lands on the screen, UIKit determines which view the finger belongs to, and this information is used for tracking gestures.

However, all OpenGL games do their main work using a single view - the OpenGL view in which all rendering takes place. This is true regardless of whether you’re drawing complex 3D graphics or simple 2D sprites. And this can mean that gesture recognisers are trickier to do, because when the finger lands on the screen, UIKit will say, “hey, the view that was touched was the OpenGL view! Job done, you’re welcome, see you later!”

So, if we want gesture recognisers, and we’re drawing using a single OpenGL view, what needs to happen is this that gesture recognisers need to be added to the OpenGL view, but are limit the areas in which they’ll look for touches to areas that depend on what’s happening in the game.

This is possible through the use of the gestureRecognizer:shouldReceiveTouch: method in the UIGestureRecognizerDelegate protocol. If a delegate implements this method, it’s possible to make a recogniser only track touches in certain areas.

This is the approach taken by Krzysztof Zabłocki’sCCNode+SFGestureRecognizers, which is a zlib-licensed extension to Cocos2D. CCNode+SFGestureRecognizers performs some very clever hacks, including dynamically creating classes that operate as delegates and using the Objective-C runtime’s new associated object support, that allow you to add gesture recognisers directly to CCNodes.

We’re using CCNode+SFGestureRecognizers in Leonardo’s Moon Ship, an adventure game that we’re looking forward to talking about further in the coming weeks and months, to support dragging items from the player’s inventory onto items in the game world.


Science Week (Tasmania)

We're very pleased to announce the availability of the official iPhone app for the Tasmanian events of the National Science Week 2012 festival. National Science Week is Australia's largest national festival and includes hundreds of events held all over Australia. National Science Week 2012 Tasmanian Events –– iPhone app

The app features:

  • full program of National Science Week events in Tasmania
  • day by day Event Calendar
  • maps showing the location of events
  • search by region or current location
  • automatic schedule updates

Grab the app on the iTunes App Store, and please let us know what you think!