Archive for July, 2010


Commercial cocos2d Code

So we’re pretty big fans of cocos2d around here as you’ve no doubt noticed, but today is a special day cocos2d-wise; it’s the two-year anniversary of our very first post about it! And the library certainly has been remarkably successful by any metric you’d care to measure, but for our anniversary post, let’s talk about commercial offerings for it, that being a particularly striking metric of success of an open source project. Practically unheard of, in fact.

But before we begin, lead developer Ricardo Quesada supports himself selling two projects -

Sapus Tongue Source Code

Complete source to the Sapus Tongue and Sapus Tongue Lite games on the App Store.


A level editor for platform/labyrinth type games which parses SVG files created by Inkscape into a Box2D world. Samples of what you can do can be seen in LevelSVG Mini Games on the App Store.

Now, we could say some obvious stuff about how best practices for a library would come from the guy who wrote it, or we could mention how insanely responsive Messr. Quesada is to support questions, but let’s not bother with that because the important point’s rather simpler; if you’re making a buck off his work, buying these projects is the very least it’s decent to do. Or if you can’t afford that straight off, at least donate directly here.

Now that you’ve done that — you have, haven’t you? — let’s take a look at two commercial offerings that have sprung up, which we’ve gone and spent some C$250 on just so that we can report on them to you, Dear Reader, because we love you so much.

First off, there’s this fellow @gaminghorror who has set up a site and is writing a book on it; worthwhile endeavours the both of them you’d think, but in the interests of full disclosure there appears a certain chilliness in relations evidenced, seems there’s a perception that the code he’s selling and we’re about to review competes with the projects mentioned above. Well, we trust our feelings on your correct priorities are quite clear already, so if he’s offering something else useful we don’t really think there ought to be a problem here, diversity and proliferation are good, yes? Speaking out of total ignorance of whatever the actual history there is and just guessing from those links, we hasten to clarify.

Any-ways, on to that source code he’s selling; it’s called Line-Drawing Game Starterkit, it’s US$179 through, well, today, and then up to US$299. As you can guess from the name, it demonstrates a certain wildly popular genre of iDevice game,


and you can check it out for free on your iPhone or on your iPad in the App Store, or read the online documentation. As for us, we installed it, and that went smoothly, defining an Xcode source tree for the cocos2d distribution of your choice is it really, and compiling the iPad target against yesterday’s v0.99.5-beta cocos2d latest almost went smoothly except for a 4.0-only flag in CocosDenshion; we’ll assume that’s their oversight not making it 3.2 compatible for iPad, not something to hold against this project, and yes it up and ran just like the demo. Code is quite clearly written and decently documented, flipping through it and running clang only found a few things stylistically different from our preferred practices and nothing that qualifies as a serious issue.

So yeah, if you’re planning on a Flight Control knockoff, we’d say it’s definitely a fine investment. Otherwise, it’s a decent example of how to structure a project in iPhone and iPad targeting versions, but not overly compelling for the price is our initial impression.

Price, on the other hand, is definitely the selling point of our second product, The iPhone Game Kit; $49 right now, $99 on September 1st. And in this case, it’s marketed as

… a complete, full-featured walkthrough to making your first video game on an iPhone, iPod Touch, or iPad. Even if you don’t have any experience at all, the Game Kit will guide you through your first lines of code and teach you everything you need to know to get your game going…

which does indeed appear to place it in direct contention with Ricardo Quesada’s offerings, and thus some skepticism of motivation is not unwarranted. But hey, you can always look at it as people who are brought into the platform by this might go on to purchase the other offerings later which are indeed somewhat intimidating to the novice no doubt; so we’re not going to rush to any judgement that there’s no redeeming value here. Besides, we dig the old school RPG thing and that’s what his demo ‘Quexlor’ is,


you can download it free as a universal iPhone/iPad version from the App Store to check out.

This download comes with a pretty basic “Publishing Guide” as well as “The Book”, a 127-page walkthrough of development, the Quexlor source, and using the Tiled map editor. And quite good indeed that one is, certainly quite a bit better than any other introductory level documentation we’ve seen anywhere. Moving on to the source code, this one includes its own distribution of cocos2d 0.99.4 so we just open the project and run it on a phone, yep works fine. Although ‘Build and Analyze’ comes up with 16 errors all of which look valid, more than a little sloppy there, tsk tsk. Flipping through it, the code looks decent quality but not as self-documenting as we like, loops like for(id o in ra) are the kind of thing we give our minions some choicely sarcastic observations on the value of maintainability as the highest metric of coding quality to aspire to when we catch them at it, but at least it is commented thoroughly. To the point where maintaining the comments would take significant effort actually which we’d say is rather overdoing it as your code should be adequately readable on its own, but hey it is aimed at beginners.

Soooo … whilst we’re not impressed enough to give this kit a wholehearted recommendation, [UPDATE: Well, yes we are as of version 3.0 now] and marketing it as “including” free content from other people both cocos2d and the game’s graphics is somewhat misleading (although granted he does provide attribution, just not prominently) it definitely is a good faith effort with significant value especially in the guidebook; hey, if we ever get around to writing That Great Turn Based RPG that we idly toss the idea of around every so often, we’ll definitely take this project as our starting point. And yes, if you know nothing about writing games and you want to start with cocos2d, it probably is pretty much the best thing out there for you.

So there you go, we figure both these options are good faith efforts and are likely a net benefit to the platform; somewhat more questionably in the second case, but it’s definitely appropriate for someone who needs a more gentle introduction than jumping into LevelSVG or the like straight off, and then they might go on to buy the more advanced stuff later. So you could argue that. Or, hey, just do what we do and buy everything! Sure, sure, some people say money can’t buy happiness … they just don’t know where to shop.


Thanks to our Gracious Commenter formotion, here’s Jump Up another paid option to check out … although at first glance it doesn’t seem to offer any overly compelling purchase case.


Custom UISwitch

So it’s getting along to Pretty Shiny Artist Time™ with your latest game project, and they come up with switches like this:


Note the non-standard metrics of the slide and the alpha halo surrounding the active area as particularly challenging obstacles to some kind of quick hack on the standard UISwitch. So we needed something custom to achieve the above. And here are the interesting looking UISwitch giblets we found for you to start with next time this kind of thing comes up:

CustomUISwitch found in homick/iPhone-Snippets is the one we ended up using; a kinda-close reimplementation of UISwitch behaviour, most notable exception being that it acts like a button with press triggering a slide animation, not the real UISwitch drag behaviour. But as the artist hadn’t provided an activated state for the slide, hey that actually solved a problem. Also it’s a bit odd that the author chose to create its own delegate for value changes, we had it just call [self sendActionsForControlEvents: UIControlEventValueChanged]; when appropriate, which fits nicely with Interface Builder’s control-drag default assignment for a UIControl.

If you’re looking for something that’s a really thorough and apparently exact behaving reimplementation of UISwitch, then we’d say that RCSwitch is probably your best starting point. Of course, that requires an actually appropriate set of component graphic pieces, as opposed to working off a superficial Photoshop mockup, so we went with expediency today.

An interesting alternative approach is UICustomSwitch which skins a UISlider instead of implementing off the UIControl base.

As a final treat, if you’d like to simply put a cute little icon on a regular switch’s slider, like this,


and you’re not nervous about making assumptions about the internal view structure of standard controls, then DSSwitch is the little tidbit for you.

As always, if you have any other UISwitch tidbits to share, let us know!



Seems that how to render TrueType fonts in OpenGL ES is something that people tend to search for a lot, and some code we’d previously babbled about that allegedly does that has disappeared off the net; so if you’re looking for that kind of thing, try checking out

FTGLES – A truetype font rendering library for OpenGL ES on iOS devices (iPad and iPhone)

FTGLES is a C++ library for rendering fonts on mobile operating systems with OpenGL ES 1.1. It is a port of FTGL. It currently targets the iPhone and iPad, with plans to port to Android in the very near future. iOS 4 is currently supported.

From the FTGL notes:

“Unlike other OpenGL font libraries FTGL uses standard font file formats so doesn’t need a preprocessing step to convert the high quality font data into a lesser quality, proprietary format.”

“FTGL uses the Freetype font library to open and ‘decode’ the fonts. It then takes that output and stores it in a format most efficient for OpenGL rendering.”

Haven’t checked it out ourselves, but it looks worth checking out if you need it, here’s the introduction; and there’s recent checkins, so apparently it’s under active development!


App Tweaking

So do you really really want to be tweaking your app a whole lot at runtime? Well, if you do, here is an article

Tweak Away

that goes through how to set things up to telnet into your running app and muck with it using the Lua Objective-C Bridge. An intriguing option, certainly…

… but be careful, otherwise the righteous wrath of the Review Team shalt descend upon thou:

… If that was not enough, this morning you got rejected again… by Apple! They discovered they could use your binary to upload Lua scripts and run all kinds of hacks on the device. Somehow they didn’t thought that was cool.

Yeah, we could actually have seen that one coming quite a ways away. [EDIT: At least, we can foresee it; note in comments below the author gently corrects us that the presented situation was actually a pastiche. Oops.] So if that idea does interest you, grab the source code here from the second post that explains how to sort this out in proper fashion.

Personally, we’d be more inclined to just have the iPhone app access changing data files/config settings from our developing Mac via http:// rather than go to all this trouble. But hey, it’s a moderately nifty thing to know how to do in any case!

h/t: ManiacDev!


And here’s a followup building on the above link: Tuning Your Game Made Easy!


Simulator Cropper

This looks like a handy goodie for your screenshot needs: iPhone-Simulator Cropper! Takes an image from the simulator with and without status bars and with and without frames, so it’s good for both development and marketing purposes:


And not only that, it can be used from the command line, useful for automating your screenshots, as discussed here. A particularly nifty feature, that!

h/t: iphonedevelopertips!


Here’s another application for this kind of thing, atScreen, which looks moderately interesting as well, particularly

  Final output can be produced using a built-in renderer or exported as an animated 3D scene, suitable for high end applications such as Maya.


Snippet: String Truncation

Here’s a handy NSString category for truncating strings on the iPhone:

Truncate a String and Append an Ellipsis, Respecting the Font Size

Particularly informative if you’ve been either relying on UIControls for your formatting or doing everything with low level CoreGraphics and have overlooked the handy methods in UIStringDrawing.h

// Single line, no wrapping. Truncation based on the UILineBreakMode.

- (CGSize)sizeWithFont:(UIFont *)font; // Uses UILineBreakModeWordWrap

- (CGSize)sizeWithFont:(UIFont *)font forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode;

And it looks like you can mix these as well as the string drawing conveniences which follow into your CoreGraphics rendering and everything works together nicely, which does rather simplify things nicely compared to using the raw CoreGraphics text functions.


Core Data Grab Bag

Here’s a few CoreData-related posts we stumbled across since our first resource collection worth your attention:

Delete the NSFetchedResultsController Cache Before Changing the NSPredicate

A nasty bug if it bites you.

coredatalibrary at Google Code

  • UITableView-based “RootView” capable of displaying all entities of a certain type with the ability to:
    • Sort based on any number of keys
    • Create sections based on a key path
    • Display section index titles, in either address book style or based on your section key path
  • UITableView-based “DetailView” capable of displaying and editing any number of attributes or relationships in a given entity:
    • to-many (ordered or non-ordered) relationship
    • to-one relationship
    • date/time
    • strings (single or multiple line)
    • numbers
    • boolean choice

Core Data and Enterprise iPhone Applications – Protecting Your Data

… In iOS4, Apple introduced data protection. It gives you the ability to encrypt the hardware keys used to encrypt your files and to erase those keys when the system is locked – leaving your file unreadable until the phone is unlocked and the keys are regenerated.

This level of protection is not built in by default though. The user has to enable it (or an IT department can enable it and force users to have it on) and your code must set an attribute on your Core Data sqlite store as well…

Core Data: Importing and displaying large data sets in Core Data on Cocoa Touch

… There is a persistent rumor that you cannot use Core Data in a multi-threaded environment. This is patently false. Core Data works very well in a multi-threaded environment but you need to play by the rules…

Re-Ordering NSFetchedResultsController

… was recently faced with having to add re-ordering for a list of entities in a UITableView. The methods I found online for accomplishing this all suggested using an NSMutableArray as the data source for the table view. That will work, but I came up with another method, though similar, that achieved what I need without having to switch from using my NSFetchedResultsController as the data source behind the UITableView…

And why, yes, of course Ray Wenderlich has a series of excellent tutorials on Core Data –like everything else, it seems — to read if you’re starting out:

Core Data Tutorial: Getting Started

Core Data Tutorial: How To Preload/Import Existing Data

Core Data Tutorial: How To Use NSFetchedResultsController


h/t: iPhone Development Blog, iPhone Devel-opment!


Here’s another collection of Core Data Odds and Ends.

And how to install your app with Core Data Starting Data.

And Working with Core Data: Schema Versioning and Lightweight Migrations.

And Core Data Lessons Learned.


Tilt Controls

Here’s a good article to read if you’re planning some accelerometer-based controls for your next project:

Lessons Learned in Tilt Controls

Hey, anybody who comes up with a calibration screen like this


has most definitely a sense of style worthy of wholehearted approval, at the very least!



This looks like a handy new little tool to check out: Ingredients!

Ingredients is a free browser for Apple’s documentation. It’s still under development, but today’s beta lets you:

  • View iPhone and Mac docs
  • Search Mac-related websites
  • Filter classes/symbols by various attributes
  • Quick Search with sane sorting of results
  • use the Filter Bar to quickly jump to methods in a class

Ingredients is also open source and available on GitHub

Just booted it up briefly — love the tic-tac-toe game, guys — but it looks pretty well done. And of course that open source thing is always attractive just in case we do really want to fix something…

h/t: iOS Development Goodies!



Here’s another in the ‘handy if you need it’ category — ever want to drag and drop an MKMapView pin? Well then, MapKitDragAndDrop is for you:

MapKitDragAndDrop is designed to bring drag and drop support to MapKit on iPhone platform, with just one single lightweight DDAnnotation and DDAnnotationView, users are able to drag and drop annotation pin and get the new coordinate…

  • Support both iPhone OS 3.1.x, 3.2 and iOS 4 at the same time, in the same source code.
  • Use iOS 4 MapKit built-in draggable support (Yes, you get Retina Display high resolution support for free!)
  • Use legacy MapKit techniques to create draggable annotations on iPhone OS 3.1.x and 3.2.
  • Use Core Animation to create pin effects you saw in built-in on iPhone OS 3.1.x and 3.2.
  • Use modern runtime, Objective-C 2.0 ABI, and LLVM 1.5 compiler.

And speaking of that last point, if you really want to be as out there on the cutting edge and all that, check out this post on necessary compiler magic:

If you wan to enable Objective-C 2.0 ABI in modern runtime (so that you can use synthesized by default feature), you need to add following flag in your $OTHER_CFLAGS:

-Xclang -fobjc-nonfragile-abi2

the tricky bit being that’s just one argument, not two as the naïve observer might suspect, so if you add your flags in Xcode you could run into issues. Yet another good argument for .xcconfig files, in our opinion.