Learn & Master

Cocos2D Game Development

            "Crack that Coconut!"

Learn Game Development with Cocos2D

Hex Map rendered by TilemapKit

The Cocos2D-SpriteBuilder game engine is a strong alternative to SpriteKit for iOS and OS X game developers. Sometimes, it can be a tough nut to crack. I’m Steffen, book author, blogger, game developer and nutcracker.

I’m most active on Stackoverflow.com where I moderate, and sometimes answer, questions on Cocos2D, SpriteBuilder, Sprite Kit, and 2D game development in general.

Since 2015 I’m working on TilemapKit, a complete solution for all tilemap game developers!

Follow me on Twitter!

My Latest Book: Learn SpriteBuilder

Learn SpriteBuilder for iOS and Android Game Development

SpriteBuilder is a visual and versatile design tool for Cocos2D. In Learn SpriteBuilder you learn how to get the most out of SpriteBuilder to create a full-featured 2D action game that you can use as a basis for your own games.

You’ll learn SpriteBuilder best practices, how to incorporate SpriteBuilder into your game development workflow, and how to use the various features of SpriteBuilder, including game physics, scrolling, menus, and playing audio assets. You’ll learn everything from the basics to advanced topics like visual effects, soft-body physics, rendering textured polygons and porting to Android.

You’ll be using both SpriteBuilder and the latest version of Cocos2D, version 3. If you have a bit of iOS development experience and you want to learn to create imaginative 2D games, Learn SpriteBuilder for iOS Game Development is exactly the book you need.

225 Responses to “Learn Game Development with Cocos2D”

  1. Howard says:

    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).

      • Howard says:

        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).

  2. jandujar says:

    the +1 google button doesn’t work.

    Nice job for Kobol2d 😉

  3. Johan says:

    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 :)

  4. Asad says:

    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

  5. Asad says:

    Hi Steffen
    Thanks the issue has been resolved, i upgraded cocos2d to new version.

  6. 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

  7. Johnny says:

    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.

      • Johnny says:

        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!

  8. Maroun Abou Tanous says:

    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.

  9. Asad says:

    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.

  10. Amanda says:

    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.

  11. Amanda says:

    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

  12. Amanda says:

    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??

  13. Jason says:

    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.

  14. David says:

    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!

  15. Paul Femiak says:

    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!

  16. SpyTech says:

    I appreciate that book. I want to read, and experience developing game for iPhone by myself. Thanks for making this kind of book.

  17. Chichi says:

    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?

  18. Paul Femiak says:

    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.

  19. Hello says:

    Any idea when the ios 5 book will make it to nook book format?

  20. Zwelfe says:

    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.

Leave a Reply