Learn & Master

Cocos2D Game Development

            "Crack that Coconut!"

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.

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 2014 I’m working for Apportable on improving and expanding the Cocos2D and SpriteBuilder documentation, among other things.

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. Daniel says:

    Hi, I bought the book and after 3 chapters I love it. I am new to the Mac and I was really struggling before I found it, now I feel I am on my way. One newbie question tough: When I load the code of the examples in XCode, I can’t run it under the Product menu so I press the upper left ‘Run’ arrow and after a warning or two it says build successful but nothing happen ?

    What do I need to do to run the examples, have the IOS simulator come up, etc. ? Thank you very much.

    • To the right of the Run/Stop buttons there’s a dropdown list where you can select what is being built. In some projects the default will be “box2d” or “cocos2d-iphone” because Xcode sorts the list alphabetically. Since those are static libraries (just code, not an app) they will build but don’t run. Simply select the scheme with the project’s name and run that, for example the “Doodle Drop” selection will run on the Simulator.

  2. Peter says:

    i just bought your book and a like it.

    I only have problems running the examples. Im working with XCode 4.2.
    I’m getting an error in line 155 of the cclayer.m in every example:

    Mutliple method “initWithColor:” found

    Semantic Issue: Sending ‘ccColor4B’ (aka ‘struct _ccColor4B’) to parameter of incompatible type ‘CIColor *’

    What must i change to fix this problem?

    Kind Regards,

  3. Collin says:

    I’ve just started the book, and under “Getting Started” you link to a installer at Cocos2d Central. I typed it in and it now, as I’m sure you know, redirects to here “http://cocos2d-central.com/files/file/6-installer-for-cocos2d-cocos3d-for-ios-mac-os-x/” and says that “the Cocos2D installer has been superseded by Kobold2D.”

    On the one hand, I’m fine with this because I like the sound of Kobold2D better, and planned to install it after getting through the book. On the other hand, I’m worried. How lost will I be following the book with Kobold2D installed, instead of the bare cocos2d-iphone?

    I tried jumping ahead to the chapter on Kobold2D, but I can’t make much sense of what was mentioned just yet.

    • Except for the startup code (AppDelegate, GameConfig.h vs config.lua) all the code works just the same in Kobold2D. If you have any questions just post them here or on Cocos2D Central and I’ll help.

  4. W.sz says:

    Dear steffen itterheim:
    i want to know which edition of the xcode do you use when you white the <>.
    Now my xcode’s edition is 4.2 which is the newest,but i found that the “cocos2d1.0.1″ looks that it not so suitable to the xcode4.2
    look forward to your answers!
    (as that i’m a chinese so my english is not so good ,wish that you can get my meanning).

  5. Paul Femiak says:

    Hello everyone. I will soon be releasing an exciting new game “Crazy Cats” built from the tools presented within the iOS5 book. Learn Cocos2d Game Development along with the tools presented within, in my opinion is the standard for cocos2d and box2d iOS game development.

    I would greatly appreciate your time to check out “Crazy Cats” app website:


    The possibilities are endless, always keep moving forward!

    • Paul Femiak says:

      Just wanted to give a final shout out that “Catastrophe” is now live and ready on the App Store:


      I changed the final release name of the game from “Crazy Cats” to “Catastrophe” after some (highly recommended) market research. This game was built from my experience learning the Learn Cocos2d Game Development book and the tools presented within the book (Physics Editor, Texture Packer, Glyph Designer, and Particle Designer). Physics Editor is very impressive and Particle Designer fun.

  6. Paul says:


    Just bought your fantastic book. However, I’ve got as far as creating the HelloWorld project and I can’t get it to build. I’ve got 25 errors to do with _ccArray. Am I missing a framework or something? I’ve posted the error transcript below.

    I’m using Xcode 4.3.1.

    Ld /Users/paul/Library/Developer/Xcode/DerivedData/HelloWorldC2D-dnwjxfgcqpugeqfegpjhwfeheqct/Build/Products/Debug-iphonesimulator/HelloWorldC2D.app/HelloWorldC2D normal i386
    cd /Users/paul/Apps/Cocos2dHelloWorld/HelloWorldC2D
    setenv PATH “/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin”
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -L/Users/paul/Library/Developer/Xcode/DerivedData/HelloWorldC2D-dnwjxfgcqpugeqfegpjhwfeheqct/Build/Products/Debug-iphonesimulator -F/Users/paul/Library/Developer/Xcode/DerivedData/HelloWorldC2D-dnwjxfgcqpugeqfegpjhwfeheqct/Build/Products/Debug-iphonesimulator -filelist /Users/paul/Library/Developer/Xcode/DerivedData/HelloWorldC2D-dnwjxfgcqpugeqfegpjhwfeheqct/Build/Intermediates/HelloWorldC2D.build/Debug-iphonesimulator/HelloWorldC2D.build/Objects-normal/i386/HelloWorldC2D.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -lz -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100 -framework QuartzCore -framework OpenGLES -framework OpenAL -framework AudioToolbox -framework AVFoundation -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/paul/Library/Developer/Xcode/DerivedData/HelloWorldC2D-dnwjxfgcqpugeqfegpjhwfeheqct/Build/Products/Debug-iphonesimulator/HelloWorldC2D.app/HelloWorldC2D

    Undefined symbols for architecture i386:
    “_ccArrayFree”, referenced from:
    -[CCActionManager deleteHashElement:] in CCActionManager.o
    -[CCParallaxNode dealloc] in CCParallaxNode.o
    -[CCScheduler removeHashElement:] in CCScheduler.o
    -[CCArray dealloc] in CCArray.o
    “_ccArrayNew”, referenced from:
    -[CCActionManager actionAllocWithHashElement:] in CCActionManager.o
    -[CCParallaxNode init] in CCParallaxNode.o
    -[CCScheduler scheduleSelector:forTarget:interval:paused:] in CCScheduler.o
    -[CCArray initWithCapacity:] in CCArray.o
    “_ccArrayDoubleCapacity”, referenced from:
    -[CCActionManager actionAllocWithHashElement:] in CCActionManager.o
    “_ccArrayRemoveObjectAtIndex”, referenced from:
    -[CCActionManager removeActionAtIndex:hashElement:] in CCActionManager.o
    -[CCParallaxNode removeChild:cleanup:] in CCParallaxNode.o
    -[CCScheduler unscheduleSelector:forTarget:] in CCScheduler.o
    -[CCSpriteBatchNode removeSpriteFromAtlas:] in CCSpriteBatchNode.o
    -[CCArray removeObjectAtIndex:] in CCArray.o
    -[CCArray removeLastObject] in CCArray.o
    “_ccArrayContainsObject”, referenced from:
    -[CCActionManager addAction:target:paused:] in CCActionManager.o
    -[CCActionManager removeAllActionsFromTarget:] in CCActionManager.o
    -[CCScheduler unscheduleAllSelectorsForTarget:] in CCScheduler.o
    -[CCArray containsObject:] in CCArray.o
    “_ccArrayAppendObject”, referenced from:
    -[CCActionManager addAction:target:paused:] in CCActionManager.o
    -[CCScheduler scheduleSelector:forTarget:interval:paused:] in CCScheduler.o
    -[CCArray addObjectsFromNSArray:] in CCArray.o
    “_ccArrayRemoveAllObjects”, referenced from:
    -[CCActionManager removeAllActionsFromTarget:] in CCActionManager.o
    -[CCParallaxNode removeAllChildrenWithCleanup:] in CCParallaxNode.o
    -[CCScheduler unscheduleAllSelectorsForTarget:] in CCScheduler.o
    -[CCArray removeAllObjects] in CCArray.o
    “_ccArrayGetIndexOfObject”, referenced from:
    -[CCActionManager removeAction:] in CCActionManager.o
    -[CCSpriteBatchNode removeSpriteFromAtlas:] in CCSpriteBatchNode.o
    -[CCArray indexOfObject:] in CCArray.o
    -[CCArray exchangeObject:withObject:] in CCArray.o
    “_ccArrayAppendObjectWithResize”, referenced from:
    -[CCParallaxNode addChild:z:parallaxRatio:positionOffset:] in CCParallaxNode.o
    -[CCArray addObject:] in CCArray.o
    “_ccArrayEnsureExtraCapacity”, referenced from:
    -[CCScheduler scheduleSelector:forTarget:interval:paused:] in CCScheduler.o
    -[CCArray addObjectsFromNSArray:] in CCArray.o
    “_ccArrayInsertObjectAtIndex”, referenced from:
    -[CCSpriteBatchNode insertChild:inAtlasAtIndex:] in CCSpriteBatchNode.o
    -[CCArray insertObject:atIndex:] in CCArray.o
    “_ccCArrayNew”, referenced from:
    -[CCTMXLayer initWithTilesetInfo:layerInfo:mapInfo:] in CCTMXLayer.o
    “_ccCArrayFree”, referenced from:
    -[CCTMXLayer dealloc] in CCTMXLayer.o
    -[CCTMXLayer releaseMap] in CCTMXLayer.o
    “_ccCArrayInsertValueAtIndex”, referenced from:
    -[CCTMXLayer insertTileForGID:at:] in CCTMXLayer.o
    -[CCTMXLayer appendTileForGID:at:] in CCTMXLayer.o
    “_ccCArrayRemoveValueAtIndex”, referenced from:
    -[CCTMXLayer removeChild:cleanup:] in CCTMXLayer.o
    -[CCTMXLayer removeTileAt:] in CCTMXLayer.o
    “_ccArrayAppendArrayWithResize”, referenced from:
    -[CCArray addObjectsFromArray:] in CCArray.o
    “_ccArrayRemoveObject”, referenced from:
    -[CCArray removeObject:] in CCArray.o
    “_ccArrayFastRemoveObject”, referenced from:
    -[CCArray fastRemoveObject:] in CCArray.o
    “_ccArrayFastRemoveObjectAtIndex”, referenced from:
    -[CCArray fastRemoveObjectAtIndex:] in CCArray.o
    “_ccArrayRemoveArray”, referenced from:
    -[CCArray removeObjectsInArray:] in CCArray.o
    “_ccArraySwapObjectsAtIndexes”, referenced from:
    -[CCArray exchangeObject:withObject:] in CCArray.o
    -[CCArray exchangeObjectAtIndex:withObjectAtIndex:] in CCArray.o
    -[CCArray reverseObjects] in CCArray.o
    “_ccArrayShrink”, referenced from:
    -[CCArray reduceMemoryFootprint] in CCArray.o
    “_ccArrayMakeObjectsPerformSelector”, referenced from:
    -[CCArray makeObjectsPerformSelector:] in CCArray.o
    “_ccArrayMakeObjectsPerformSelectorWithObject”, referenced from:
    -[CCArray makeObjectsPerformSelector:withObject:] in CCArray.o
    ld: symbol(s) not found for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    • Symbols not found sound like the CCArray class wasn’t compiled into your project. Make sure it’s added to your project and added to the (correct) target as well.

      • Paul says:

        Thank you, Steffen.

        There were several files that were included in the project but weren’t being compiled for some reason. I had to delete them and re-add them to get it to work.


  7. I.Dream says:

    Currently in a test application I am building, I want to create particle bursts that appear when two objects collide. The main object will remain visible while the 2nd object will be removed. In the place of the 2nd object (that was removed) will be the particle burst. How should I set this up? Could you please guide me through the steps in creating this particle burst in cocos2d? Thank you!

    • I.Dream says:

      by the way, I really love your book!

    • The easiest way is to spawn the new particle effect just before you delete the 2nd sprite/object. Then you can still access its position and other properties, and assign them to the particle effect so that it appears at the same location. If needed you can also do [sprite.parent addChild:fx] to add the particle effect to the same parent as the sprite. This may be necessary to ensure correct draw order or relative positioning.

  8. PeterPan says:

    THE BOOK IS SEXIST I WILL NOT STAND FOR IT. Pg. 66, “If you work with an artist, make sure SHE is aware of this issue”…………………………………………

  9. Tinkerbell says:


  10. xzessmedia says:

    Hi, i also love the book, its really good for newcomers and even experienced ios programmers who want to expend the experience with cocos2d.

    theres one point i am a bit confused.

    i have a CCTMXTileMap and 2 Layers, a MapLayer and a HudLayer.
    The CCTMXTileMap lays on the MapLayer.
    I move the MapLayer to fake camera movement.

    When i added the the CCTMXTileMap as a child for the MapLayer it should be enough to just set the position of the layer to move the tilemap, isn’t it !? (well this is how i move the layer)

    While my movement works, i want to move the layer to a specific location so that a spawn point gets centered on the map. Something like CenterMapCoordinate (which fits to the Tiled Map Coordinates for the Spawn Point / Object Layer Objects) when i hardcode the position i can get what i want, but not by using the tmx’s objects layer properties

    When i load the Spawn Coordinates by loading it as a dictionary like…

    – (void) LoadMap:(NSString *)filename
    MapFile = [CCTMXTiledMap tiledMapWithTMXFile:filename];
    PlanetLayer = [MapFile objectGroupNamed:@”Objekte”];
    [self addChild:MapFile];

    //Planet suchen und Position setzen
    NSDictionary *planetProperties = [PlanetLayer objectNamed:@”MainPlanet”];
    CGPoint MainPlanetPosition = CGPointMake([[planetProperties valueForKey:@”x”] intValue], [[planetProperties valueForKey:@”y”]intValue]);
    NSLog(@”Pos X: %f PosY: %f”,MainPlanetPosition.x,MainPlanetPosition.y);
    [self ScrollMap:ccp(-MainPlanetPosition.x,-MainPlanetPosition.y)];


    it loads the wrong coordinates…

    I know how to recognize touches and how to iterate through the CGPoints of the objects, but simply it doesn’t work :)

    So the second and more important question is:
    Must i move the object layer if i added the whole CCTMXTiledMap as a child of the layer?
    It seems that i have to move the objects layer also, because my touches wont get recognised but i always have to scroll the map to find a location and then no touches are recognised but why? This is why i added it as a child for PlanetLayer.

    I would send you the same in german, english is sincerely not my native language :)
    Would be very very kind if you would take some minutes to drop me some lines per mail.

    Wäre wirklich nett wenn Sie mir eine kurze Nachricht schicken würden, dann kann Ich Ihnen auch Sourcecode schicken und würde gerne ein paar Worte hinzufügen.

    Viele liebe Grüße

    and all thumbs up to you!

    • You may need to use the “convertTo…” methods of CCNode to convert the coordinates of one node to that of another. But it shouldn’t make a difference with CCLayer since that has it’s origin at 0,0 as well. But of course this changes when you reposition (move) the layer.

      Touch locations are always relative to the screen, and in UIKit coordinates (0,0 at top left corner in portrait mode). You can’t use the touch location directly without converting it with director’s convertToGL method.

      So my suggestion is to make very simple, easy to isolate tests (for example, add tmx layer directly to scene) and check which of the coordinate conversion methods you need. It helps to draw some debug info to see where points are at and then you can easily see if that’s what you would expect, and compare the ‘is’ with the ‘should’ to draw conclusions.

  11. Have you implemented Cocos2D Scenes in to the UIPageViewcontroller?

    Hi Steffen, thanks to you (and your book) I got the cocos2D CCScene to run in the UIKit.

    What I want to be able to do is implement CCSenes in the UIPageViewController. I can get a single scene to run in the PageView,(just like you explained in your book), But when I try to turn the page it crashes. That is where I am stuck.
    Here’s a link to a tutorial I used http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_UIPageViewController_Application#The_Xcode_Page-based_Application_Template

    I can post the relevant code if you can help me .

  12. Joel Meler says:

    Hi sir,

    I have two, easy to answer, questions. I am new to programming and everything that has to do with game development. I was thinking on first getting a book to learn objective c as a language, and then proceed into the game development. So is this a good idea, or i can go into your book without learning objective c?

    and second, does your book cover graphics in every context? or just game programming.


    • A working knowledge of Objective-C is very helpful for my book. On the other hand a programming language is best learned within the context of an actual app, so I would recommend to learn both Objective-C and cocos2d at the same time since they’re not mutually exclusive.

      Graphics are covered as far as cocos2d is concerned and as far as is commonly used in games, meaning: sprites, labels, animations, tilemaps and so on. What I don’t explain is low-level graphics programming with OpenGL, since the whole point of cocos2d is to hide the complexities and technical nature of OpenGL programming. I added simple examples to illustrate how to add custom OpenGL rendering to a cocos2d app though.

  13. Joel Meler says:

    Thank you for your response, i really appreciate it. One last question though, (this is something that has been on my head for at least three months and i haven’t been able to figure it out), how do you do graphics as good as the ones on angry birds, or tiny wings, or cut the rope? can you do these using cocos2d? because I’m looking at videos on youtube about games that were made with cocos2d and the graphics are weak. I feel like graphics are one of the most important qualities of a video game.


    • How well can you sketch, illustrate and paint? That and talent, skill, experience define how well the resulting game will look. It has very little to do with the game engine.

      You can always hire people to do the things you can’t do (not nearly as well) yourself. That’s why Angry Birds looks so much better than 95% of all cocos2d games made by a single, indie or hobbyist developer.

      In other words, great-looking games that are also fun to play are almost exclusively team efforts of experienced developers. And the way to get there is to make the games that you saw in the youtube videos. ;)

  14. Joel Meler says:

    So then actual drawings on paper could be scanned and used as pictures for
    Sprites and animations? What I’m trying to ask is if you can get drawings on paper to be your graphics, because I have a great artist in my grade.

  15. Joel Meler says:

    Thank you for all your help Steffen.

  16. Hero says:

    i am a Chinese,but also i am a new cocos2d programer.i wish I can get help from you! Thanks everybody!

  17. Jeramy says:

    I’m currently reading the book Learn cocos2D game development with iOS 5 and am going to the websites provided in the book for the Source Code, but both links direct me to the source code for a book called earn iPhone and iPad cocos2d Game Development. Is this the same source code?

    • No, that’s the first edition. You have the second edition of the book (iOS 5 in the title). You can get the source code for both editions here, links are in the table a the bottom: http://www.learn-cocos2d.com/store/book-learn-cocos2d/

      • Jeramy says:

        I just started reading this book, and now cocos2d-iphone-2.0 is out. How much stuff is going to be different in this book. I’ve already run into a snag on page 26 where it says you can change the text label orientation using kccDeviceOrientation(whatever), and I’m searching through the whole cocos2d workspace and there is no such thing now.

        Should I hold off reading this book until an updated version is released?

        • There’s many smaller changes regarding the API in cocos2d 2.0. I’m currently working on updating the book to the third edition, which will use cocos2d 2.0 and ARC. Release will be this summer, most likely in August.

  18. N says:

    Oh… I was excited about kobold2D but the need of Xcode 4.2 sort that ruined my wish. Not everyone migrated (or wants) to Lion.

    • Xcode 4.2 is also available for Snow Leopard, it’s not a Lion-exclusive. You can get it from Apple’s developer downloads page, search for Xcode to find the Snow Leopard version. Kobold2D should still work with Xcode 4.1 if really needed. It’s just that I don’t test it for compatibility with Xcode 4.1 anymore.

      As a developer, there’s really no way around migrating to newer Mac OS versions. Apple typically only supports the current and previous versions of OS X for development. So you can choose to stay with the previous version for a while, but after the release of Mountain Lion you’ll eventually be faced with having to upgrade to either Lion or Mountain Lion in order to publish apps to the App Store.

      • N says:

        Thank you for the valuable info. In app store the XC4 was Lion only. I’m not atm a fee member dev (my biz is actually web dev not app dev) but later when I apply to the paid program for start do mobile apps I will then download and use the 4.2 version. For now as basic developer I must still use 3.2.6 (that I’m downloading now for update over my 3.2.5). :)

        True about Mountain, but I really don’t want upgrade to Lion in this machine because I learned badly from mobile experience as a user that upgrade OS is always “cripple” the machine. When Mountain arrives I should be using a i7 machine, so nothing to worry then.

  19. Markus says:

    Hi Steffen,
    thanks again for your great book! We bought it (yeah, it’s worth every penny) and developed our first iPhone App – a funny game – from scratch with its help: Roosterama, a high quality turn based, game center enabled chicken longjump game with funny animations…
    Please let us know what you think!
    Thanks and kind regards!

  20. Joel Meler says:

    What can i do if im having trouble understanding the books, just nothing clicks??

Leave a Reply

Powered by WishList Member - Membership Software