Archive for January 28th, 2011

28
Jan

Review: Cocos2d for iPhone 0.99 Beginner’s Guide

So as we mentioned in our latest cocos2d links collection, the nice folk at Packt Publishing provided us a review copy of Pablo Ruiz’s book Cocos2d for iPhone 0.99 Beginner’s Guide,

Cocos2D For iPhone Beginner's Guide.jpg

and we’ve gone through it now for you, Dear Readers!

TL;DR

If you’ve completed a cocos2d game … no, this is not a reference; you’ll probably find some tidbits of value, but I wouldn’t make it a high priority purchase. You probably guessed that from the ‘Beginner’s Guide’ name.

However, if you are a complete beginner to game programming … no, the name notwithstanding, what this does cover will be over your head, and it doesn’t cover things not related to cocos2d directly a beginner needs introduction to. We heartily recommend the iPhone Game Kit for you.

If you’re a programmer new to the iPhone platform … you’ll struggle with the Objective-C, no doubt. Come back after you’ve done a program or two, got the Cocoa memory model down, and so forth.

So if none of those apply, presumably you know something about programming iOS already at the UIKit level and now you want to get into programming games, and you need a walkthrough of cocos2d design principles and the associated development toolchain? Excellent, you’re the person this is actually appropriate for — as long as you’re fully aware that much of the book has already been overtaken by recent developments.

EXCURSUSES

First off, take a look at the chapter list in this cocos2d forum announcement. Topic selection is good, progression is straightforward. No complaints about the overall structure then, this is indeed a well designed introduction to cocos2d.

However …

One big problem with doing a book like this is that you will inevitably be overtaken by events. Let us take this exchange from the cocos2d forums:

cell-gfx: Reading through the timer example in the book on page 28, you use the schedule:@selector method of scheduling an update to your node. However, when I refer to the cocos wiki, it says to use scheduleUpdate…

pabloruiz55: Yes it would, but as the chapter was written a while back the scheduleUpdate method didn’t exist :)

scheduleUpdate was added in 0.99.3. The version of cocos2d distributed with the sample code as of right now is 0.99.1. The current version of cocos2d is 0.99.5. The changes are substantial enough that people are encountering some difficulty applying the book’s code with the current release. So it’s pretty difficult to recommend something wholeheartedly when you know people are going to struggle with it through no fault of their own; at the very least, if you publish a book like this you should at least keep the samples up to date with the current release, and a list of updates/errata such as the above, I’m thinking; in a designated blog for book discussions, if nothing else.

Same problem applies to the chapters about tools. It goes over the Zwoptex web version for sprite sheets, not the native version or Texture Packer. The fonts chapter, we were wincing at the Hiero and Angelcode discussion: “Both are very good tools” — no. No, they are not. Granted that Glyph Designer is brand spanking new right now and no doubt was completely unheard of as the book was written, but someone picking up cocos2d today really needs to be informed about that. Again, this is the kind of thing that would be most properly addressed by something like a designated blog, or perhaps errata updates mailed to registered users.

Another example of this problem is that even the design walkthrough, which is generally good, can be significantly in error. We were brought up short on page 47 of the PDF for instance, with

“When you quit your game … the applicationWillTerminate method will be called. This is a good time to save your game’s state…”

Ah … no. Not on iOS 4. (Unless you go to some effort to get that behaviour). That would be a perfectly acceptable oversight in a book released in July last year. In December? Not so much. If lead times are so long that a statement that’s been wrong for six months can’t get corrected for publication, then there really needs to be some mechanism for distributing errata.

Moving on, we were mildly disturbed by the code samples in general. Picking on the Chapter 4 ‘ColouredStones’ example in particular, we load it up to find it’s looking for SDK 3.0. Sort that, we get

“Code Sign error: The identity ‘iPhone Developer: Pablo Ruiz (4LFH26A558)’ doesn’t match any valid certificate/private key pair in the default keychain”

and it’s set at project and target level both. OK, we can sort this out in 15 seconds, but a beginner cannot. Messr. Ruiz overlooking this before uploading, hey we can let that slide. Technical reviewers? Not so much, guys. Especially when we get around to Build and Analyze:

Screen shot 2011-01-29 at 2.21.33 AM.png

Okay, if you’re working for me, and you check in code with any warnings or analyzer results, we will have words. If you check in code with an analyzer error “Incorrect decrement of the reference count of an object that is not owned at this point by the caller”, we will have harsh words. That code which would only compile on the author’s machine and that contains significant errors made it through to the downloads? The reviewers have not done their job acceptably. Yeah, our standards are high. So should yours be.

That said, with a little coaxing we did get all three of the game samples to run, and they are well chosen to give a good overview of the functionality discussed throughout the book; so we’re only mildly disturbed, there is a good bit of value here.

We could nitpick a while more, but you’ve pretty much got our feeling now; the book is well designed for what it is, which would be more accurately named “Walkthrough of cocos2d Development for the iOS Programmer” than a “Beginner’s Guide”, that being somewhat of a misnomer. However, it’s well designed for the state of cocos2d development prior to iOS 4, which makes reading it now mildly problematic. And that goes even more so for the source code, which is not only somewhat outdated but really should have had much better review before letting it loose on the readers. Valuable, yes; exemplary, not by a long shot.

So clean the code, update it to current recommended practices, update the tools chapters, and put a process in place for updates to stay in sync with continuing cocos2d development; yep, we’d give 2nd Edition a nine, nine and a half as an excellent introduction to cocos2d. What we’re reviewing today … yes, we’d recommend it to someone who asked for the best way to start getting up to speed on cocos2d we knew of, but would make a point of telling them to read the caveats above. Six and a half, seven, that’s about the best we can muster up. Still, a fine effort by Messr. Ruiz, and we do hope sales go well enough to merit an update!