Book: Learn Cocos2D Game Development

First Edition

Xcode 3, iOS 4, Cocos2D v0.99, Zwoptex, VertexHelper, Hiero.

Learn iPhone and iPad Cocos2D Game Development book cover

Second Edition

Xcode 4, iOS 5, Cocos2D 1.0, TexturePacker, PhysicsEditor, Glyph Designer. NEW: UIKit Integration, Kobold2D & Cocos3D. Learn more.

Create compelling 2D games with Learn cocos2d Game Development with iOS 5. This book shows you how to use the powerful Cocos2D game engine to develop games for iPhone and iPad with tilemaps, virtual joypads, Game Center, and more.

Best of all, Learn cocos2d Game Development with iOS 5 will have you making games right from the very start. It guides you step-by-step through the creation of sample games. These fun examples are modeled after popular App Store games and teach you key concepts of the Cocos2D game engine and relevant tools like TexturePacker (texture atlas), PhysicsEditor (physics collision shapes), Particle Designer (particle effects), Glyph Designer (bitmap fonts), and others.

This book offers a rock-solid introduction to creating games made entirely with Cocos2D and little or no iOS 5 SDK and OpenGL code. It also details alternative implementations, identifies the best free and commercial tools for cocos2d game development, features coverage of the author’s improved Cocos2D game engine (Kobold2D), and even helps you enhance your game’s marketability on the App Store.

What you’ll learn

  • The process and best practices of mobile game development, including sprite batching, texture atlases, parallax scrolling, orthogonal and isometric tilemaps, bitmap fonts, touch and accelerometer input.
  • How to enhance your games using the Box2D and Chipmunk physics engines and other cocos2d-related tools and libraries.
  • How to add UIKit views to cocos2d and how to add cocos2d to UIKit apps.
  • The ins and outs of the Kobold2D development environment for cocos2d and its preconfigured libraries, including cocos3d and Lua.

Who this book is for

The book is aimed at beginning game developers looking for an easier and even more powerful way to create compelling 2D graphics using OpenGL and Objective-C. It is assumed that the reader will have some knowledge of object-oriented programming and the Apple and iPhone/iPad developer environment.

Table of Contents

  1. Introduction
  2. Getting Started
  3. Essentials
  4. Your First Game
  5. Game Building Blocks
  6. Sprites In-Depth
  7. Scrolling with Joy
  8. Shoot ’em Up
  9. Particle Effects
  10. Working with Tilemaps
  11. Isometric Tilemaps
  12. Physics Engines
  13. Pinball Game
  14. Game Center
  15. Cocos2D With UIKit Views (NEW in 2nd Edition)
  16. Kobold2D Introduction (NEW in 2nd Edition)
  17. Out of the Ordinary

Learn Cocos2D Book Reviews

Book Details

Book Resources

39 Responses to “Book: Learn Cocos2D Game Development”

  1. Joey says:

    Hey there,

    first of all I’d like to thank you writing a book not only refering to APIs, but really teaching the readers the logical reasons behind pieces of code. I just recieved my book and I can’t stop learning. I found it rather hard to begin in Cocos2D, all those different online tutorials and ways of making a game. This book really gives you a solid amount of knowledge in order to go and create whatever you like.

    Normally I don’t write such comments but this one deserved it!

    Cheers, Joey

  2. herve31 says:

    Hi Steffen,

    I just finished to read your book ! It’s very good !

    Just a mistake print, in chapiter 10, P 213 … 234, there is a bad header (CHAPTER 11 :…) and not CHAPTER 10.

    Now i m starting my cocos2D developpement.

    Thank you for your book !

  3. luis says:

    the book says something about using the resourses provided by the book, but i just got the bok alone, without cd or something extra. Where do i get the alien.png the book mention?

  4. maroun abou tanous says:

    wonder if we should read the book (first version) with the cocos2d new code v1 ,
    or you will be releasing a new book with a newer version ?

    Btw im thinking of reading your book learn cocos2d but install kobold2d and same time read the code of the new projects that u have included ?
    is it a bad idea , do u suggest a better solution . i read many times ur answer to such question which was , kobold2d makes it easier by its new 13 projects but the problem is i dont know what is CClayer so i must have a book and not look syntax coding !
    thank you

    • You can use v1.0 with the first edition of the book if you’re not afraid to rename a few classes. The details are listed here:
      http://www.learn-cocos2d.com/2011/05/learn-cocos2d-book-source-code-update/

      Otherwise stick to v0.99 and then later upgrade to v1.0. The biggest difference between those Cocos2D versions really are just the renamed classes.
      The second edition of Learn Cocos2D is still scheduled for end of October and will be updated for 1.0 and contains two new chapters and a lot of improvements and corrections.

      Yes, Kobold2D gives you a lot of code to look at but if you haven’t worked with cocos2d before you still need the basic introduction. That’s what my book is for. About 98% of what you learn from the book applies to Kobold2D as well, and the second edition contains an introduction to Kobold2D to make transitioning easier.

      I’m also considering to make the node system (scene, layer, node, sprite, label, etc.) a lot easier for Kobold2D, because if you think about it, scenes and layers are superfluous while the node class itself is underutilized. But that system probably won’t appear in 2011, it’s something I have in mind for the future.

  5. maroun abou tanous says:

    Thank you for your fast reply Steffen,
    I wanted to be sure that you are making another book version cause i live in Lebanon and ordering your book from amazon or any other site is dramatic and takes a lot of time. I will wait until u release the new book (by end of October) .
    I will be reading your sample code of kobold2d.
    Excuse me for this question but i always wonder . isn’t making a game and releasing it more beneficial than writing a tutorial or books ? just for curiosity why does a man like you waste his time rather than make a huge game ?
    In all cases good for me there is men like you :) .
    thank you for everything and for kobold2d open source and hope you success.

    • I enjoy improving the process of developing games for me and for others. Actually creating a game of my own isn’t that interesting or exciting to me, it’s the process that gets you there.

      Also, it’s much easier and more satisfying to connect with game developers, than it is to connect with (and satisfy) gamers.

  6. NonprofitCoder says:

    Your book just arrived in the mail, and I’m excited to get started!

    When I download the 1.0 source code, I get a “unable to extract” error. The 0.99 source code seems to work just fine. I’m on Lion.

    Is there something I’m doing wrong?

  7. Orlando Chogas says:

    Hi Steffen,

    Will the book truly be available on iBooks soon?
    I am really waiting for that to happen.

    … maybe I could buy the pdf on Apress, but I have to tell you: I have been for 1 whole afternoon trying to understand how to buy it as eBook, but the webpage is incredibly user-unfriendly, and it just take me into circles (after all this time I still can not find how to give them my credit card data, nor where could that “buy this title as an ebook” button be hidden!… there are only those “add to wishlist” and “my wishlist” things that does not seem to serve any purpose). And I have been unable to find the option for a pdf ebook anywhere else.

    So my point is: could it be that they have some issues with their system? or is it that I did finally became senile? (if that is so, could you or some other kind person here guide me a little in the right direction?)

    Any help will be greatly appreciated!; and well, Steffen, thank you very much for this second edition! looks very promising in the previews!

    • To be honest, I know nothing about sales, versions, availability, release dates of the book, or the Apress website. On occasion I hear about a release date (from Amazon mostly) but that’s about it. ;)
      I can only assume that since the first edition is available on iBooks, the second edition will be too. I don’t know when though.

      • Orlando Chogas says:

        You are right, but here is something that could interest you:

        “the first edition is available on iBooks” … but ONLY on USA, not even Deutschland.

        I did search for the book before on iTunes, but could not find it (at least the first version should have come up, but not).

        Now I followed your link and it sent me to this:

        “Your request could not be completed.
        The item you’ve requested is not currently available in the Chilean Store, but it is available in the US Store. Click Change Store to view this item.”

        And if I change to US, then it appears even in a normal search, but of course I can not buy from US itunes store. Going back to Chilean Itunes Store the book becomes absolutely invisible again.

        I was actually living in Deutschland just 1 month ago, (for some years) and your book is invisible also from my account from there.

        So your book seems to be available through iBooks/iTunes only for USA. I certainly imagine that your plan was to open overseas to sell, so probably THAT is indeed an issue.

        If you would like to, please help this guy (and most probably others) to get a copy of your book.

        Much appreciated.

        • I wish I could but I have no influence on distribution channels, and so on. That is all done by Apress.

          I didn’t even know the iBook version was for US only, purely by coincidence I had changed the iTunes Store to US shortly before I searched for the book.

  8. Orlando Chogas says:

    oh!, it seems ill have to get one US credit card then, somehow, he he.

    Anyways, nice the chance to chat with you! Thanks for your prompt answers.

  9. Maroun Abou Tanous says:

    Steffen good morning,
    Im back to send you a message :) hope you wont be bothered, tell me please if you are .
    I want to point at something in box2d chapter :
    Density Restitution and Friction
    you explained them briefly specially the restitution = if its going towards 1
    that means it will keep the same speed if it increase the speed will be higher after it hits (i understood that)
    But about the density and friction , you didnt care for them while working with the walls, the bumper … only for the ball you assigned the 3 values..
    can i know why ? are they important or the fact its out of the book scope (pure physics) . i hope you could cover a bit more of these , maybe 3 lines for each will make people like me get it :$.
    Btw i am a web developer (for banks) using servlets so you know my background with games is 0 :D excuse me
    And hope your good these days

    • The attributes of a body are explained in the Box2D manual, section 6.2.

      Density
      The fixture density is used to compute the mass properties of the parent body. The density can be zero or positive. You should generally use similar densities for all your fixtures. This will improve stacking stability.
      
      The mass of a body is not adjusted when you set the density. You must call ResetMassData for this to occur.

      Friction
      Friction is used to make objects slide along each other realistically. Box2D supports static and dynamic friction, but uses the same parameter for both. Friction is simulated accurately in Box2D and the friction strength is proportional to the normal force (this is called Coulomb friction). The friction parameter is usually set between 0 and 1, but can be any non-negative value. A friction value of 0 turns off friction and a value of 1 makes the friction strong. When the friction force is computed between two shapes, Box2D must combine the friction parameters of the two parent fixtures.

  10. Maroun Abou Tanous says:

    Ty Steffen, Your just too good.
    Almost done from the book, as my first review … i was so happy everything is explained in a perfect way. Your fast replies and support are the most appreciate it.
    Gonna add your websites to my family blogs and Facebook. I own you the support you give us here .
    Again wish you more luck and if you need anything i can do , ill be glad to help
    Take care,
    Maroun

  11. Markus Reidt says:

    Hi Steffen, first I want to express how great it is to have this book (I’m reading the 2nd edition)! The explanations are very clear and the knowledge transferred is invaluable stuff!

    Many thanks to you for writing this book! It’s so incredible helpful…

    Until now there is only one thing I don’t get: On pg. 54 you are talking about transitions and refer to the HelloWorld game from chapter 02. You suggest to use the code snippet on that page to test transition. To do that you use class CCSceneTransition. Unfortunately this class seems not existent. Not even the cocus2d online API reference knows something about CCSceneTransition. What’s the issue on this one?

    Greetings from Hamburg,

    Markus

  12. Maroun Abou Tanous says:

    Dear Steffen,
    One little question so i know where to search to learn it:

    lets say an exemple :
    In box2d
    I got a bullet and a wood , both are dynamic bodies
    i hit the bullet directly toward the wood || i hit the bullet bounced and hit another objects than hit this specific wood.

    Lets say i want to break the wood into parts (ill use animation) but the problem is , how can i know the point of intersection so i can determine if i hit the middle or top or bottom of this body wood,
    Shall i use raycasts ? if raycast is my solution isnt it hard to determine where it hit after a several bullet bouncing (so 1 line wont be enough).
    Again please tell me if u dont like questions so i can stop bothering you :D but ur the only person i know who can help :) ty

  13. harish says:

    Steffen,
    I going through this book. I love the way the book’s been written.

    I finished till chap 5 with the source code. I have been able to compile the code.

    Coming to Chap 6 onwards, none of the code is getting complied.
    I get the following errors (199 errors in total )

    error: stdarg.h: No such file or directory
    The source file is stdarg.h at line: #include_next

    error: float.h: No such file or directory
    #include_next (source : float.h)

    I am kinda new to Xcode. It will be awesome if I can get past this.

    thanks,
    harish

  14. harish says:

    I forgot to mention, I am using Xcode 3.1.4 and using Simulator 3.0 SDK
    regards
    Harish

    • Xcode 3.1 is way over 2 years old. The source code for the first edition was tested with Xcode 3.2 and the second edition code with Xcode 4.x but should also work with Xcode 3.2. You should consider to upgrade Xcode, especially since you’re new to Xcode.

      As for “#include_next” – it is not a meaningful statement. Maybe a typo?

  15. Misha says:

    Hey Steffen!

    I bought today your book (latest version for iOS 5). I have the latest XCode and Lion installed. Whenever I try to open one of the projects in the downloads available at Apress for the book, the project build successfully, but it is not executed in the Simulator. I have no problem on projects I write myself or from other online tutorials.

    Thanks!

    • Make sure you have the correct scheme for the actual project selected (upper left corner of Xcode window, dropdown view). If the selection says “cocos2d” or “box2d” then it will only build that static library, and static libraries don’t run. Use the scheme that has the name of the project, like “Doodle Drop”.

      If that’s not the problem then a reboot should help. Infrequently Xcode just won’t start an app, and occassionally it’s persistent until you restart Xcode or reboot.

      • Misha says:

        Hey Steffen,

        I am so silly an inexperienced, thanks! I was building the cocos2d library…

        This is the second version of your book I purchase, I loved the first version but could never really study and exercise on it because of job commitments.

        Thanks for the help!

  16. Nicky Gerritsen says:

    Hi,

    On page 8 of the eBook (page 11 according to Preview) you state cocos2d-javascript.org as the website of the Cocos2d for python project. This seems to be incorrect ;) . (I got my eBook from aPress)

  17. Michael Rowe says:

    Have been working thru the second edition, and have run into a snag, I find that I learn best, typing in the code myself. In chapter 5 the follow is very different, I.e. lots of source modules, etc. so I worked thru the first set where you get to see the scenesandlayers app. At this point I realized how out of sync I was, so tried to compile th ScenesAndLayers02 project. I am running the latest version of Xcode and I got a build fail: CCLayer.m
    “sending ‘ccColor4B’ (aka Struct _ccColor4B) to parameter of incompatible type ‘ClColor*’

    Have you seen this? Is there a compiler flag that should be set? Thanks for a great book so far…

    • Hmmm, I don’t know of any Cocos2D method that uses a CIColor* parameter. Sounds to me as if you forgot to #import a header file and Xcode started to think you wanted to call a method of the Cocoa framework, or you were accidentally creating a Cocoa framework class instead of a Cocos2D class. Hard to say without seeing the code that causes the error.

      • Michael Rowe says:

        I was trying to compile the sample code directly as it was downloaded from the APRESS site. Example 02 from chapter five…will look for missing headers

  18. Pcasso says:

    Hi
    Was using the code. The code builds but does not runs on latest iOs5 device or simulator.Any settings to be changed?

Leave a Reply