Under The BridgeUnder The Bridge

Joypad Controllers

Here’s a few links for stuff that may be of interest putting together controls for That Next Great Game:


A collection of input methods for Cocos2d iPhone game development. It includes a Joystick, a dPad, and Buttons, all entirely skinnable and customizable…

The LevelSVG joystick code, separately available.

Good discussion here.

h/t: iPhone Friend via iOS Development Goodies!


So if you’ve haven’t looked into these new UILocalNotification thingys in iOS 4 yet, there’s a good introduction here:

iPhone Programming Tutorial – Local Notifications

but there’s a couple somewhat rough edges around them, unless we’re missing something:

1) Recurrence interval must be an CFCalendarUnit flag. Just the flag. So you can set something to recur every day, or every week, but not every three days. That seems rather odd.

2) Seems the application’s badge is always set to the number included in the notification, not the number of notifications that have triggered. So unless you go to the trouble of clearing out the pending queue and fixing the numbers in each of them every time the thing you’re notifying about is handled, or each time that something’s inserted in the queue of notifications, there’s no way to have the application show an accurate number of items pending.

Are we just overlooking stuff that’s completely obvious, Dear Readers, or are these actually the moderately annoying shortcomings which they appear to be?

How Social Games Ate Our Lunch

So you left as baffled as us by this whole Farmville thing? Here is an excellent article for you:

How Social Games Ate Our Lunch

… It’s unintuitive to think that games where you actually do not ever directly interact with another person could have a community, but what social games do is generate an asynchronous cloud of persistent community formed by the constant exchange of gifts, tools, and requests sent by other players. It’s generosity-driven, but transactional – if I send you a gift, I’m feeling happy because I helped you out (especially if I’m responding to a request you’ve put out), but I’m also hoping you’ll send me something back. And the more I send and receive, the more I plant, the more I return every day (or more than once a day) – the more hardcore my play becomes. Watch a hardcore FarmVille player. They move fluidly and attentively around the tiniest change in mechanics, and play not for some whimsical dollhouse experience but for tight, fast, controlled optimizations, seeking the fastest path to a clear goal, and putting in as much time as it takes to get there…

Okay, but we’re still not seeing, like, the point here.

… What World of Warcraft did to Everquest’s mechanics – making them smoother, faster, and more elegant, and so earning unprecedented millions of players – FarmVille, though we don’t like to admit it, did to World of Warcraft. FarmVille distills the active components of a game down to a handful of clicks, and massively leverages social and viral communication channels to create the feelings of shared mission and victory, all while carving out a player-expressed space in the online world. And while it’s doubtful that even its creators would call FarmVille “elegant,” it is the first step in a new evolution of games, new (and resented) the way World of Warcraft was in the beginning – and its mechanics are so powerful that it has compelled a head-popping number of new gamers even without being polished the way WoW was…

Yikes. We’re not completely sure whether to be flabbergasted or horrified at this evolution of gaming, because we sorta have the apparently old school idea that a game ought to be, you know, fun, and these seem a lot more like work, but hey, the argument does hold together well, so if you’re interested in game design it’s definitely worth a read!

h/t: @gaminghorror!


[EDIT: Discontinued.]

Feel like snooping around other people’s apps? Hey guess what, there’s an app for that:

atPeek is a developer tool designed to explore and display resources found in iPhone applications. Its simple and intuitive interface allows to effortlessly examine normally unaccessible application details. atPeek can export individual assets or entire folders and its unique feature is its ability to decode both crushed iPhone PNG images and PVR textures back into standard PNGs.

Even if you’re not particularly interested in other people’s stuff, these QuickLook plugins might be handy:

You can separately download the PngUncrush (32-bit and 64-bit Universal) and PvrUncrush (i386 only) QuickLook plugins, which we have developed for atPeek. Simply copy them to /Library/QuickLook folder and you will be able to preview iPhone crushed PNG images and PVR textures right from the Finder (or any other QuickLook enabled applications).

h/t: iOS Development Goodies!

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 [EDIT: Used to] support 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.

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 learn-cocos2d.com 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; [EDIT: Now withdrawn] 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.

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!

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!

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.