Learn Game Development with Cocos2D
The Cocos2D for iPhone game engine is the premier 2D game engine for iOS and Mac OS X 2D game developers. It’s no secret that sometimes it can be a tough nut to crack. I’m Steffen, book author, blogger, game developer and nutcracker.
What is it that you want to know?
- Could Cocos2D be any easier?
It certainly can be, with Kobold2D and KoboldTouch! Without it, you’re hardcore. - Where can I find more advanced Cocos2D tutorials?
Read my iDevBlogADay articles, most of them Cocos2D tutorials on advanced subjects. - Is there source code for that?
Of course, it’s all in the LearnCocos2D github repository. - What if I like to hear your voice?
Uhm, if you don’t mind broken accents and the occasional incoherent rambling then listen to the Cocos2D Podcast with me and Mohammad Azam. (iTunes) - Where can I watch and learn about Cocos2D?
Check out the featured channels on the LearnCocos2D Youtube Channel and view my LearnCocosTV Show & Tell progress reports. - Can I get an answer from you personally?
Certainly! But due to the amount of questions I get I’m limiting it to the KoboldTouch member helpdesk and Cocos2D related questions on Stackoverflow.com. - Where can I find more tutorializing Cocos2D devs like you?
Here’s a quick list: Ray Wenderlich, Mohammad Azam, Alex Curylo, Johann Döwa, Bucky Roberts, iPhoneGameTutorials and many more. - I wouldn’t mind spending a few $$$ for code and education, but where?
Try my Line-Drawing Starterkit source code, my Learn Cocos2D book, the various Affiliate Products I help to sell and of course KoboldTouch with the Essential Cocos2D reference documentation. - What’s your affiliation with Cocos2D?
Other than being an avid Cocos2D user, fan and critic: none. - Can I hire you?
Nope, sorry. I have my hands full working full time on my own projects (see above). I’m still waiting for that clone I ordered …
Connect with me!
Join Cocos2D Central and start a discussion. That’s the best way to reach me. I also answer questions on StackOverflow.com.
You should also subscribe to my newsletter to receive updates and never miss anything important.

You should definitely follow me on Twitter if you use Twitter. If you don’t, now would be a good time to start!









Thanks. Are the differences in the way the template sets up the project, and the naming of classes as “Scene” vs “Layer”, as in “HelloWorldScene” indicative of the change in version philosophy, or is there a general explanation of how one can tie the new source to the existing book edition. I am still leaning towards buying yours, but a bit of a mapping guide can help
The Scene or Layer naming is mostly subjective. There weren’t really dramatic changes in cocos2d from 0.99 to 1.0. So when I updated the code, 99% of my changes were about changing the cocos2d class names. The rest were a couple functions whose parameters changed, and those were quick fixes as well.
If you think of the philosophy of cocos2d (and its templates) vs my code, there is a difference. I was very careful not to let my code quality degrade. I pick a style and stick with it. For me, it’s excruciating to look at cocos2d’s template code because there’s no style, and the formatting is all over the place. For a public and popular library you’d expect it to greet its new users with better code.
That’s something I’m going to change with Kobold2D (http://www.kobold2d.org).
OK, You sold me. I downloaded the iBook, and may just shoot you an email now and then if something doesn’t map well. I’ll do so on the blog if I think it’s something that would help others, too. Now the race is on to say what comes out first: your second edition or the iPhone 5! Then again, maybe that will require a third edition…
That and the cocos2d 2.0 version that is under development.
I’m guessing the sequence will be: iPhone 5 (September), Learn Cocos2D 2nd Ed. (October), Cocos2D 2.0 (late this year, if at all).
the +1 google button doesn’t work.
Nice job for Kobol2d
Hi Steffen, your book looks good, does it come with source on cd or something? And if i buy the kindle version would the source be available for download? Keep up the good work
The source code is available for download from the book’s store page or from Apress. Everyone can download the source code for free, so it doesn’t matter which version of the book you buy.
Thanks for responding, I see on the link page you gave that there is a second edition almost here, is it worth waiting for that rather? Or does it cover completely different topics than edition one? thanks
The biggest changes are the two extra chapters and compatibility with Xcode 4, iOS 5 and cocos2d v1.0. Since the 2nd edition is supposed to come out in two weeks I’d say it’s well worth the wait.
Hi Steffen
I am using your cocos2d and i have build a simple game based on your code, but as you know the new sdk has been launched and i upgraded to new xcode, there are some issues of cocos2d with xcode 4.2, Please can you guide us to solve the issues we are facing in new xcode.
Thanks
Asad
I didn’t write cocos2d. Nevertheless it should work in Xcode 4.2 / iOS 5. What’s the specific issue you’re seeing?
Hi Steffen
Thanks the issue has been resolved, i upgraded cocos2d to new version.
Hi Steffen, I’m a graphic artist taking the plunge into programming. I just want to thank you (again) for writing your book. I just studied the section from your book chapter 13 “The BodyNode Class” (using the super method) …Amazing!!! At this point, I only understand the concept. But I must experiment with this to really know how to use it in my own projects.
- Lars
Hi Steffen,
Is there anything for people who already have your first cocos2d book? Something like the Apress “Companion eBooks” promotion ($10 for the eBook if you have already purchased the print copy)?
Cheers!
I believe that deal is in every Apress book (second to last page). I don’t have my copies yet so I can’t say for sure.
They state in their 2008 announcement (see http://express-press-release.net/52/Apress%20Extends%20$10%20Companion%20eBook%20Offer%20with%20Every%20Print%20%20Book%20Purchase.php ) you need to have the book in your hands to be qualified for the e-book rebate.
Does any of you know whether it’s still the case? I’d like to get the e-book version ASAP, while I’d use the cheapest (overseas) delivery method for the printed version. Then, however, I’d beed for the book to physically arrive first. Doesn’t Apress have any way to communicate with Amazon to decide whether a given printed book has indeed been paid for?
I don’t have my copy yet, but the previous edition had that offer on the second to last page of the book. I believe this is a standard offer for all Apress books as I’ve seen it in several titles already.
From the instructions of the first edition, you need to go to a specific website address, register your copy and answer a randomly generated question about the book to receive the promotional code.
Hi,
I meant if I have already got the first book, is there any discount for the second. I would just like the ebook
btw, there is a sale this monday – all ebooks are just $15 each! That is pretty good. And, you are in the top 5 on the Apress best sellers – well done!
Just want to thank you for the new book . and wish you luck with it !
A little review :
after reading 100 pages in less than 5 hrs (i already read the first 7′th chapter from the old version book) .. i can say for JUST PERFECT . you did very well ! chapter 3 was a great improvement, now i understood things i didn’t understand with your old book.For who’s concerned don’t think twice to buy Steffen book.. its easy and written in a sequent way … anyway i am going to continue now i am excited to see the other enhancement that u have done.
And by the way i read your article about the pirating for the first book , don’t worry i wouldn’t know of you if they didn’t do that . my first copy was from them “pirates” but when i read it .i felt its not fair to steal such work , from a person who really worked on his book . each sentence , each word … nice done and always update us of new releases .
Have a nice day all
Thanks for the kind words, highly appreciated!
I don’t actually think about the pirated copies, there’s very little value lost to piracy and like in your case, sometimes it’s even a win. Piracy was always with us and will be for as longs as digital things can be copied (that is to say: always). I also don’t regard piracy as stealing, I’m very vocal against this false statement. I believe it was put in our minds that piracy equals stealing because in a sense that makes Piracy more “marketable” for those who are against it. Piracy is closer to fraud actually, because no actual valuable thing is being stolen through the act of piracy. Instead the legal way of owning that thing (buying it) was bypassed. It is comparable to “sneaking into” a concert or similar paid event. If instead someone else’s ticket would have been stolen to gain access, then the person who owned the ticket would no longer be able to attend that event. For piracy to be stealing or theft, it would have to have the effect that some other party would lose the possession of the item they previously owned. And there is no instance where piracy can do such a thing.
Hi Steffen
I have developed a game iShooter based on your code in the book after reading the book, thank you for the great book i have learned so many things. BTW here is the link for the game.
http://itunes.apple.com/us/app/ishooter-helicopter-game/id477945785?mt=8
Thank you for your time.
I have a question concerning the use of “*”, is the placement abritrary? I come from an AS/400 background were coding is a little more structured. For example in chapter 4 you code CCScene *scene.. and CCLayer* layer.., would CCLayer *layer.. be the same? Thank you for writing this wonderful book, it is helping me finally make the transition from business programming to game programming!
It’s the same, the whitespaces are ignored by the compiler, so you could also write “CCScene * scene;” if you wanted to. It’s entirely a subjective decision about programming style.
Personally I favor to place the * next to the datatype because to me the pointer * belongs to the underlying datatype, not the variable.
However, there’s one caveat to watch out for: “SomeClass* aPointer, notAPointer;” <– in this case only the first variable would be a pointer. I do avoid declaring multiple pointer variables in the same line for that reason.
Thanks Steffen that makes sense, I’ll have to watch out for the cavet!
Hi Steffen,
I have another question for you concerning chapter 4.
I started the project from scratch and have ended up with an alien showing a white square and just one spider. I noticed a lot of code in AppDelegate.m that was different from the source you provided, but everything else seems to match perfectly. I can run the source you provided and it works perfectly on my new iPod. I changed the code in AppDelegate to match your source, but still have the same problem. Any ideas what might be wrong?
Thanks…Amanda
Steffen,
I just noticed that my version of DoodleDrop only has 1 target defined for iOS SDK 5.0 I seem to be missing cocos2d libraries. Could this be the problem??
Is there a plan to add a new chapter regarding saving game data?
Saving isn’t very complex nor complicated to warrant an entire chapter. For example most collections (NSArray, NSDictionary, etc.) already have writeToFile and loadToFile methods, and for the rest there’s NSKeyedArchiver. Also with Cocos2D 2.0 there’s a chance that finally NSCoding support will be added.
I amn currently reading “Learn COCOS2d Game Development with iOS 5″ and enjoying it. Are you planning on authoring a print book on Kobold2d?
Thanks!
I currently have no plans for a Kobold2D book but certainly the intention should the opportunity arise.
Hello everyone. I have been close follower of this book and own both the original and iOS5 version. I am releasing a cocos/box2d iPad game built from the tools presented within the book. I have several apps and this will be the second game I have released using these specific tools. I am most pleased with this app of all.
I would greatly appreciate your time to check out my latest game, “Mad Cats”. (iPad specific):
http://itunes.apple.com/app/mad-cats/id488651594?mt=8
The possibilities are endless, always keep moving forward!
I appreciate that book. I want to read, and experience developing game for iPhone by myself. Thanks for making this kind of book.
Just a quick question
I have added UITextField to my cocos2d project but it seems that the initial loading time is very poor, (about 1-2s delay), is there any way to ‘preload’ it?
forgot to say Happy new year
Are you sure the UITextField is causing the delay? That would be very unusual, delays in that range are normally related to loading (caching) textures or audio files.
Hello Steffen,
I am in need of some Jedi wisdom. Regarding “Listing 13-19″ of your iOS5 book, how would one go about extending the PostSolve event to make use of and access to impulse? Previously I have done this within the ContactListener class but I am rather stuck on executing it with the new method.
Any idea when the ios 5 book will make it to nook book format?
I can’t say, I’m not informed about when or if a certain eBook version will be released. That’s up to Apress.
Hi Steffen,
I purchased your first and now the new book… First of all, thank you very much for your descriptions they help me a lot to find my way to develop my own little game… However I have a typical newbie question regarding the fps display… I realized after updating to cocos2d 1.0.1 and Xcode 4.2 that with the “Helloworld” template my framerate constantly fluctuates between 59 and 60 fps even the scene just shows the label “Helloworld”. I made sure that on my iPad there are no other apps running in background, but I remember from a previous version that the framerate stayed at 60 fps. So is it normal that this happens? Thank you for your fast reply…
This can happen, in particular if the framerate update rate is very high. Check the ccConfig.h file, I believe it’s in there where you can change the frequency of FPS counter updates as a #define. I believe it’s 0.1 by default and I usually change that to 0.2 or 0.3 because I’m more interested in ensuring that the framerate is constant rather than noticing even the slightest and smallest spikes. If the update frequency is low, even rounding errors can affect the fps. Also it may depend on whether the fps value is cast to integer. If it is, then even the value 59.99999 will give you 59 fps even though it’s much closer to 60 fps.
Thank you a lot… Setting this value to 0.2f helped…