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.

What is it that you want to know?

Learn Cocos2D Game Development

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!

221 Responses to “Learn Game Development with Cocos2D”

  1. TomL says:

    I got 2 editions of your book now, but how to best program for both OSX and iOS is still unclear. I reckon the only real difference if I program the game for both platforms would be that I need to handle the user input in a different way that iOS only. In the examples in your book you have different classes all take user input, by making them a delegate of the “TouchDelegate”. But doing it this way would cause a lot of code to be rewritten for the OSX version. The best way as I see it, is to have two separate classes handling all the input for both platforms. But I have not been able to find any good examples how this is best done, are you aware of any?

    • Certainly. There’s Kobold2D which wraps input behind KKInput, which in turn is driven by concrete classes like KKInputKeyboard etc. Depending on the platform the concrete classes may be nil so any calls to keyboard on iOS returns default values (ie no key is pressed). That makes it easier to write cross-platform code because there’s no need to litter project’s code with #ifdef.

  2. Dill says:

    Hi Steffen,
    thanks for your contributions to cocos2d. It has made a number of things a lot simpler and understandable for some of us. Recently, I posted a question on stackoverflow (http://stackoverflow.com/questions/16101596/making-a-box2d-body-move-in-a-sine-wave-type-motion) which you commented on. I am trying to use the approach you recommended but I’ve hit the wall. I am not even sure how to set the gravity scale for a range. I’ve been at it for quite a while, I would appreciate it if you could explain your solution a bit further for me. Thanks.

  3. Mikolaj says:

    Hi in my whole life I’ve read about 40 it books connected with programming (generally speaking I’m a flex developer but I also code in java and obj-c html) or maybe more but this one was the best… I never had so much fun when developing something really solid great book and I can only said congrats and keep up doing good job

  4. sumingliang says:

    I am chinese developer.I learn Cocos2d by this book.

    Thanks for all you have to do,thanks for all you have to say.

  5. Sky says:

    Hey Steffen, I have your newest addition of Learn Cocos2D and I am dealing with tile maps. Is there a way to put a shader or some similar transform on my isometric tile map to make it appear with True Perspective, like this – http://blog.ponoko.com/wp-content/uploads/2010/12/isometrictut.jpg

    Is Kobold Touch capable of that, or do you know how I can achieve something similar, thanks!

    • I don’t think a shader could do that unless the shader is drawing the tilemap. Meaning it almost certainly can’t be a post-processing effect and it may require or at least would be a lot simpler if the tilemap were projected onto a 2D plane in 3D space, perhaps with curvature already applied by the geometry. But I don’t know, I’m not an expert in shaders or 3D projections.

  6. glen says:

    Hi Steffen, great work. Please keep it up. I’ve learnt tons of stuff from your book and this site. I have an issue that I recently posted on stackoverflow I hope you wouldn’t mind taking a look at it for me. The link is below:


  7. CocosKat says:

    Hi Steffen. This is in regards to your reply to my previous question:

    Original question:
    “I have a CCSpriteFrameCache that I use for various game graphics. However, I also have a CCLayer where I display various images in a UITableViewCell (which are the same images as in the game). I’d rather not add all these image files to the project so that the UITableViewCell can use them (since they are the same as in the CCSpriteFrameCache).

    Just wanted to double check to see whether it’s still true that you can’t use a sprite from a CCSpriteFrameCache as an image in a UITableViewCell. If not is there any alternative besides adding the image files directly to the project?”

    Your reply on November 23, 2013 at 10:23 was:
    “That’s still true and will always be true. Cocos2D uses OpenGL. OpenGL content is drawn to a OpenGL view, and other views are either above or below that view. What you’re trying to do is the equivalent of sneaking in another view between, say, a UIButton’s underlying button image and the button text. It just won’t work.”

    I was able to work around this by doing the following however:

    //Get CCSprite from the CCSpriteFrameCache
    CCSprite *foodItemSprite = [CCSprite spriteWithSpriteFrameName:[aDict objectForKey:@"FoodItemImageName"]];

    //Convert the CCSprite to a UIImage
    UIImage *imageFromSprite = [self renderUIImageFromSprite:foodItemSprite];

    //Put that UIImage into the table cell
    cell.imageView.image = imageFromSprite;

    - (UIImage *) renderUIImageFromSprite:(CCSprite *)sprite {

    int tx = sprite.contentSize.width;
    int ty = sprite.contentSize.height;

    CCRenderTexture *renderer = [CCRenderTexture renderTextureWithWidth:tx height:ty];

    sprite.anchorPoint = CGPointZero;

    [renderer begin];
    [sprite visit];
    [renderer end];

    return [renderer getUIImage];


    This appears to work ok. Do you see any risks to this approach? The UITableView is on a CCLayer that just has a static background; there is no action on this layer; it’s basically just a static information screen.

    thanks for your expert opinion
    btw, I love your book – it’s one of 2 absolutely essential reference books I have for Cocos2D and iOS

  8. frank says:

    Hi Steffen.

    How can I simulating mud/slime like this (http://www.emanueleferonato.com/2012/05/16/simulating-mudslime-with-box2d-bitmaps-and-filters/) by cocos2d-html5 ?

    the example is AS3 in flash. I want to know how to implement it by html5

    Thank you ^_^

  9. Nehru Juman says:

    Hi Steffen,

    I’ve been working on an ios roguelike for about two years now (with cocos2d of course) and you’ve helped me on several occasions on stackoverflow – thanks! I’ve been having doubts about whether 2d is relevant now as mobile technology continues to accelerate. What do you think?

    • Check the App Store(s) and count the number of 2D vs 3D games. I think you’ll find that most of them are 2D, and the highest-ranked / best-selling ones are 2D either. While the best 3D games are more often than not really high end productions by companies like EA and Epic.

      Even among the 3D games you’ll find plenty which only utilize 3D for visuals but the game could as well be implemented using 2D graphics.

  10. hanbaofeng says:

    I am a reader of your Learn cocos2D 2 Game Development for IOS(3rd edition).
    It’s a very nice book.
    I am using cocos2D 3.0.Some of the contents of the book and the code does not apply to V3.0.
    May I ask you to tell me that what are major differences between 2.X and 3.0, and how to correctly apply the 3.0 version of your book.
    Thank you very much!

    • Major differences, hmmm. A lot yet little. Mainly the API has been redesigned for 3.0, so many classes/methods will be found under a different name or use different parameters. Future releases will introduce more core changes, like a new renderer. It’s difficult to say exactly what has changed how. I suggest to work with the book and v2.x – that’ll make learning cocos2d concepts a lot easier, and then you’ll also find it easier to start a new project with v3.0 or convert and existing one.

Leave a Reply

Powered by WishList Member - Membership Site Software