abitofcode

COCOS2d-X by Example Beginner’s Guide by Roger Engelbert (Packt Publishing)

Cocos2d-X by Example Beginner's Guide
I’ve been looking forward to a Cocos2dx book ever since Cocos2dx branched from Cocos2d-iPhone and this book met my requirements perfectly.

It’s a beginners guide but some existing programming knowledge is assumed, if you’re familiar with Cocos2d-iPhone the book removes much of the pain in transitioning to Cocos2dx.

A quick read through the table of contents reveals a lot of content crammed into just over 200 pages but the structure is good and I found myself flying through the chapters.

Each Chapter clearly lays out at the beginning what you will learn. Careful thought has gone into the order that the content is introduced and from the off you’re building game mechanics rather than menu systems and splash screens, an approach that reminds me of Emanuele Feronato’s Blog.

Techniques are introduced once and repetition is avoided allowing more material to be covered in fewer pages, the code for all the example projects is available for download and commented.

It’s written in a friendly style and much like the StanfordU iOS lectures cuts through waffle;

So what is a 2D framework? If I had to define it in as few words as possible, I’d say: rectangles in a loop.

Having avoided C++ for as long as possible I was a little dubious as to how the book would cover it. Enough help is given in the early chapters to get on with using the framework and this was all that was needed to get stuck in. Familiarity with C++ will grow as you use it and with Cocos2dx being open source you can pick up techniques looking through the source code.

The book aims to develop your Cocos2dx skills by following through the development of 6 games. As well as basing each game around a different game mechanic the author also throws in some practical game development techniques along the way. Rapid prototyping introduced in chapter 4 helps to keep the reader focussed on building something playable rather than getting bogged down too early with the detail.

The games

  1. Air Hockey
  2. Sky defense
  3. Rocket through
  4. Victorian Rush hour
  5. Pool
  6. Eskimo

Screenshots of the games are available over at Roger Engelberts blog

Amongst the techniques discussed;

Multi touch, supporting multiple resolutions, roll your own collision detection, Sprite sheets, bitmap fonts, actions, animation, Particle systems, Drawing primitives, vector maths, rapid prototyping, placeholder sprites, platform game collision code, side scroller terrain generation, Box2d, cross platform development …

The final chapter ‘Code once. Retire’, covers setting up a hybrid iOS/Android project. It’s this type of chapter that usually goes out of date before the book hits the shelves however the chapter does attempt an explanation of the process rather than a list of actions to blindly follow.

The Appendix ‘Vector Calculations with Cocos2d-x’ is a great resource for anyone struggling with subjects like dot products and angular based speed.

I really enjoyed this book, Roger has done a great job at making the subject both friendly and approachable and the example games cover a wide range of techniques. If you’re currently turning work away because you don’t support Android development this is a great place to start.



edit: There are a few deprecations in the latest release of Cocos2d-x that are not reflected in the book or errata, if you’re having any problems the following link may help;

Deprecations since the book release

Until the errata is updated the following may help;

p32 AppDelegate.cpp -> applicationDidFinishLaunching (setResourceDirectory deprecated)

    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
 
    pDirector->setOpenGLView(pEGLView);
 
    CCSize screenSize = pEGLView->getFrameSize();
    ...
 
 
    //if device's screen width is greater than 768, use high definition images
    if (screenSize.width > 768) {
        CCFileUtils::sharedFileUtils()->setResourceDirectory("hd");
        pDirector->setContentScaleFactor(2);
    //or else, use standard definition
    } else {
        CCFileUtils::sharedFileUtils()->setResourceDirectory("sd");
        pDirector->setContentScaleFactor(1);
    }

Try

    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
 
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
 
    CCSize screenSize = pDirector->getWinSize();
    ...
 
    //if device's screen width is greater than 768, use high definition images
    if (screenSize.width > 768) {
        CCFileUtils::sharedFileUtils()->addSearchPath("hd");
        pDirector->setContentScaleFactor(2);
    } else {
        //or else, use standard definition
        CCFileUtils::sharedFileUtils()->addSearchPath("sd");
        pDirector->setContentScaleFactor(1);
    }

p33 AppDelegate -> applicationDidFinishLaunching. (fullPathFromRelativePath deprecated)

    SimpleAudioEngine::sharedEngine()->preloadEffect( CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("hit.wav") );
    SimpleAudioEngine::sharedEngine()->preloadEffect( CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("score.wav") );

Try;

    SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename("hit.wav").c_str());
    SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename("score.wav").c_str());

Overview:

  • Learn to build multi-device games in simple, easy steps, letting the framework do all the heavy lifting
  • Spice things up in your games with easy to apply animations, particle effects, and physics simulation
  • Quickly implement and test your own gameplay ideas, with an eye for optimization and portability
  • Enjoy building the games as much as you will enjoy playing them

Win Free e-copies of Cocos2d-X by Example Beginner’s Guide

You’ll be pleased to know that I have teamed up with the nice people at Packt Publishing to organize a Giveaway of Cocos2d-X by Example Beginner’s Guide

3 lucky winners stand a chance to win e-copies of their new book.

How to Enter?

All you need to do for a chance to win is head on over to the book page and look through the product description of the book and drop a line via the comments below this post to let us know what interests you the most about this book. It’s that simple.

Deadline

The contest will close on May 30, 2013. Winners will be contacted by email, so be sure to use your real email address when you comment!

29 Comments

  1. What interests me most about the book is the game dev techniques discussed in the book via examples.
    I’m a high school student. I’ve played around with a few engines before, like libgdx, but this is my first try with a c++ engine.
    From the moment I read about cocos2d-x, I knew it was perfect. Now, it even has integration for an open source multiplayer framework!
    However, I must admit that I’m having some difficulty getting off my feet on this one.
    So judging by the reviews, I think think this book is gonna be a HUGE boost to me.
    So I’d be really grateful if i won a copy of the book.
    Thanks
    Rishav

  2. What I see that I really like about the book is that it describes the details of various types of games that can be developed using cocos2d-x instead of spending the whole book going over a single game. It is really nice to see more momentum behind the c++ port of cocos2d, I really love all of the cocos projects.

    Looking forward to this book, it should be a great help to all learning the cocos2d-x framework.

    Thanks,
    Jarrod

  3. I’m looking forward to reading this book so that I can get started with game development and cocos2D which has been of interest to me for quite sometime.

    The chapter Code Once Retire looks pretty interesting it will be good how to code games with cocos2D.

    Thanks Aaron

  4. What interests me most about the book is the book shows you how simple is creating a hybrid game for multiple platforms. Also the owners of this book will have a chance to examine six games developed in this book. I have been programming with c++ for many years. Now it’s time to use this open source framework to create cross platform mobile games. So i’m very interested in receiving a copy of this book. Thanks.

  5. Good initiative!

    I’m interested by this book because I never took the time to work with Cocos2D-X and it would be a good opportunity for me to finally start the adventure.

    Best,
    Yannick

  6. Using C++ and Cocos 2D x sounds great as ive been learning C++ for games. I also like the sound of learning by easy steps and then using your own ideas later on.

  7. I’m a cocos2D objective-C developer and i’m interested in cross platform engine and cocos2D-X is a good choice so i really wanna learn this :-)

  8. I’ve waited for a book like this, that explains cocos2d-x using examples. There is just no better way of learning something than learning by example!

  9. I’d like to see the whole process of creating game. I’d really glad if the book show the process of the whole creation of the game from the game menu, gameplay, to its game mechanics. From the product description I can’t find something I would really love to find in this book. I really hope that there are some chapter which explain about how to integrate cocos2d-x with the payment system and ads library for iOS, Android, and Windows Phone which is really important for game developer. And I think it will be a really good idea to include the explanation or link to some good tool for cocos2d-x development either free or paid such as cocos-builder, spine, cfxr, tiled, and so on, so the reader can have a good idea about the whole of game development process.

  10. The force is strong with this one!

    I’d love to read and figure out how to port Floris for Ouya.

    Thanks for this!

  11. I’m a cocos2d-iphone developer and i’m looking a cross platform framework. Known about cocos2d-x but never had time to check it out, so this book could be a good opportunity to start.

    Best Regards
    Seba

  12. What interests me about the book are the various game examples covered in each chapter, particularly the Victorian Rush Hour game. It would be nice to know how to develop these kinds of games using C++ and cocos2d-x.

    I hope this book breaks the barrier in trying to learn the numerous CC-related classes and tricks/nuances/pitfalls related to understanding the framework (e.g., the use of release/retain).

  13. To me gamedev is the most challenging area where a programmer may apply his skills. And it’s also where the most fun is concentrated. Wrong – overconcentrated. I only study programming at the moment, but I want to end up in the gamedev niche some day. Why? See above.
    If this book can teach me how to make cool games with cool effects, which can be easily ported to many platforms, isn’t it the suremost way to my dream?

  14. Compared to Cocos2D the one with X at the end offers more sweet options, if you ask my opinion. The number one to me is that I can use it on Windows, even though I understand that I have to switch to MacBook some day to become a serious iOS developer. The only problem until now was absence of a single source where all the necessary info could be obtained from to start coding games. Now we have this book – well, we want to have this book.
    I already have a project to implement using Cocos2DX but it’s only the first one of many. And I want to devote those many games to my daughter and other little kids who will play my games. So I am not the only one who needs that book.

  15. I want to learn how to develop the game. This book is a must to me as the air. I’ll be glad to get it. I’ll read it from beginning to end.

  16. I’m very interested in the cross-platform development aspect of this book. After playing a little with the cocos2d-html5 version I’m excited to experiment with native mobile game development.

  17. Also in 28 may my birthday. Please create this great gift for me!

  18. I’ve always wanted to learn Cocos 2D, but the fact that it was limitted to Objective-c was always a problem for me (no mac at home), I’d love to start using the c++ port

  19. I’ve played around with Cocos2D briefly in the past and always wanted to get back in to game writing.

    The trouble is it’s hard to find a book that teaches by example.

    This book looks like it solves that issue.

    Plus, seeing as the world of game development is deeply rooted in C++ it seems like the perfect opportunity to teach myself and get some experience outside of Objective-C.

  20. This book looks really interesting. I would like to read it and specially to get to know how to work with Box2d. I have an idea for a game and I would like to crack on to get it done.

    Thanks!

  21. I like the way the author structured the contents of the book using simple games as examples to introduce and explain core concepts of game development using cocos2d-x. I really like that the author included an introductory chapter to C++.I also like how every sample game included in the book explain different concepts from Drawing Sprites to Complex physics with Box2d.
    I think learning by example is a great way to get started in game development and this book looks like it would help me a lot.

    I’ve been looking forward to this game engine for quite some time and this looks like the best opportunity to me to get started.

    Thanks bro!

  22. I initially wanted to start with Cocos2d-X, but chose Cocos2d-iphone instead because there was more reading material to start with.
    What interests me the most is the chapter about rapid prototyping and the “Code once. Retire” chapter

  23. As an ActionScript programmer this book seems to be a good and at the same time deep introduction to cocos2d and c++ game development. I will try my luck here before purchase my own copy. Thanks to the author and this site!

  24. I’ve just learned about Cocos2d-x just a while. It’s by coincidence that I know a book about it just made a while ago and also by coincidence that I know about this contest (today is last day lol).

    I’ve read some samples of the introductory chapter, it said the author expect the reader to be in Mac and xCode environment. Outside my interest about Cocos, I’m more interested to know and try the examples are whether they’re working in Windows and Visual Studio environment or not.

  25. So far most of my programming experience has been in Pascal (and websites). I love the indie community and have spent loads of time chatting and hanging out with it’s members.
    What’s most appealing about this book is that it’s versitile, but it doesn’t just teach you how to code. It teaches you how to make a game, which is totally awesome 😀
    (oh and im fed up of creating very buggy 2D games in Unity (buggy because I don’t really know C#)).

  26. Hi,

    I am in gaming company working as development manager. I am interested in learning Cocos2Dx and found this book worth learning as it has reference to real game examples.

  27. I think the best thing about cocos2d-x is it’s cross-platform nature. I’d love to get into android development but don’t have time to learn a new platform and get back up to speed with java development — all on hobby time taking away from my iOS projects I have so many of. Cocos2d-x would go a long way towards that and a book like this would be invaluable. I’d also like to have a hard look at box2d beyond some basic demos. (Chipmunk pro has kept me happy!) Sounds like this book woul dhelp there. And, selfishly, I’d like to play around with the newly ported TMX generator with cocos2d-x as well. =)

  28. This book looks great. I’m excited to get the chance to win one and get moving on cross platform development with cocos2d. Between the general cross platform / cocos2dx info and the look at 6 games created with that in mind I think this will be an excellent learning experience.
    Thanks

  29. I’m interested in the cross-platform support so I could convert my current Objective-C demo to C++. I want to be able to work on my project on an OS other than the mac. The Box2D and game controls implementation would be very helpful.

    Thank you.