Category Archives: cocos2d-x

Cocos2d-x Book Available Now from [Packt] Publishing

It has been difficult for developers new to cocos2d-x to learn this game framework but a new book just released will make it much easier.

The book, “Cocos2d-X By Example Beginner’s Guide”, provides an entertaining way of learning to develop cross platform games using cocos2d-x. 

There are several game examples, Air Hockey, Sky Defense, Rocket Through, Victorian Rush Hour, and Eskimo to demonstrate all the capabilities of cocos2d-x with special attention to the physics engine Box2D.  The Appendix provides additional reference information on Vector calculations that help in rotating objects and controlling angular base speeds.

The material is presented well and even provides an overview of C++ as the book goes along so it is perfect for the beginner that wants to learn to make games on multiple platforms (iOS, Android, Blackberry, etc) but also provides in depth information that even the advanced cocos2d-x programmer will appreciate.


If you sign up on the PACKT pub website you will be sent special offers, sometimes up to 60% off their Ebooks.  You can also find this book on Amazon and many other places including the link below directly from the publisher.

Buy it now from:

The author of the book also has a great blog with additional tutorials where the algorithms are shared for many common game task using various languages and frameworks, visit it at:

Angry Ninjas Sling Shot Game Starter Kit for Building an iOS Universal App!


There is an increasing number of very good tutorials on game development using various game engines.  The one shown below is exceptionally well done.  Although targeted at iOS development it is easily extended to Android and other platforms using cocos2d-x as shown below with the game running on the Android Kindle Fire.


Angry Ninjas Starter Kit: An Easy to Customize XCode Project PLUS High Definition Video Documentation

 To get the cocos2d-x C++ version also please Buy Now.

CartoonSmart offers top line tutorials for various game engines.  The one discussed here is the “Angry Ninjas Starter Kit”.   We purchased this to review the quality of the tutorials and were very surprised at how much details the tutorial covered.

This Angry Birds type of game goes through all the details to provide a basis for a physics game that is similar to the Angry Birds series.  The videos describe in detail on how to customize each parameter for YOUR game. Check out the details of the tutorial here.

Angry Ninjas Starter Kit Marketing info from CartoonSmart:

Sling shot games are quite popular in the App Store aren’t they? Well why not ride that wave and create your own popular app. This template is ready for you to make a great game out of it. All that’s required is a bit of time on your part to build some fantastic levels and add your own artistic twist. We’ve done the hard part. Now you get to do the fun part!

Like all our iOS Starter Kits the project files are included with video guides (accessible online or offline) covering every detail of modifying the app for yourself.

Some Basics about the App Template:

  1. Runs at 60fps on the iPhone 4, iPhone3GS, iPod Touch and iPad.
  2. Supports high resolution images for the Retina Display iPhone.
  3. Preference settings for the iPad or iPhone (for example, you can change things like the stack location, screen pan speed, throw power of the sling shot, etc. by changing simple variables)
  4. Uses Box2D, an advanced physics engine for realistic collisions (the same as another well-known sling shot game) We like the physics as they are, but you are welcome to toy with gravity, the accelerometer, or any other property to drastically change the game.
  5. Supports as many levels as you want to build.
  6. The in-game Menu will show 10 sections, and each section can have multiple levels. Players will have to complete all levels in a section before the menu unlocks that section to jump to.
  7. Level progress is saved in the NSUserDefaults. So even if the game quits, players will have a variable saved for the number of levels they have completed.
  8. High scores are also saved in NSUserDefaults
  9. You can set the number of characters to toss per level and how much score is required to pass the level.
  10. You can set bonuses per level for the number of characters that haven’t been used to pass the level.
  11. You can change the layers of background art on a per level basis. The clouds, hills, and ground plane are all separate scrolling pieces of art.
  12. Drop in your own .mp3 files for sound fx or background music.
  13. Includes three sound preferences which get saved even if the player quits the game. So players can enable or disable Sound FX, Voice FX, or Ambient FX ( or Background Music )
The Extra Special Cool Features….

This wouldn’t be a “Cartoon” Smart Template if we didn’t add some easy ways to make this game really come alive with your own art and animation.

Here’s some of the artistic highlights…

  1. It is incredibly easy to add a variety of shapes to your level’s stack with built in vector definitions for the collision environment. For example: squares, triangles, circles, trapezoids, parallelograms, hexagons, octagons, pentagons are preset properties for your stack object. Want to know more? Skip to 00:07:21 for details in the demo video below
  2. Includes two animated impact FX that can be played anytime a stack object breaks (you can add as many more as you like). Different FX animations can be applied to different objects or enemies.
  3. Supports custom break animations for stack objects or enemies. So if you want to include even more animation for a specific object breaking apart you can.
  4. Stacks are incredibly easy to build. We recommend using an art program like Flash or Photoshop to design your stack then just copy the center x and y locations of each object into XCode. Skip to 00:18:53 for details in the demo video below
  5. Two lines of very easy code add each stack object or enemy to the stack. All your properties for the object are defined in one line. Usually YES or NO values for options like: breaksFromNinja , hasAnimatedBreakFrames, damagesEnemy, breaksOnGround, makeImmovable. Skip to 00:10:44 for details in the demo video below.
  6. Every Stack Object or Enemy can have a custom point value.
  7. You can add as many different slingshot characters as you like, depending on level or the order they get thrown in.
  8. Slingshot characters have different artwork frames for poses like “standing in line to be thrown”, “blinking” , “in air”, “roll”, “roll and impact”, or “on the ground”. You can add as many different poses as you like and choose when they appear.
  9. Enemies can have damage factors. So it may take more than one collision with a ninja or stack object to damage the enemy enough to be destroyed. In our demo video you’ll notice the enemy gets a bandage or two after being collided.
  10. Enemies can also have separate animated frames for breaking (for example, the enemy in the template disintegrates )
  11. Choose between embedded images or a font for the post-object break Scores (which float above the object that broke). Currently the template uses images for scores in values of 100,500,1000, 5000 and 10000.



Converting Cocos2d to Cocos2d-x for Multiplatform support

At Neonchalk, we converted this cocos2d Objective-C code to C++ to be used with cocos2d-x which allows the game to be deployed to all devices that it supports.  Today they demonstrated cocos2d-html5 which is amazing.  We will contact the author of “Angry Ninjas” to see if the cocos2d-x version can be shared with others or perhaps they will do a tutorial on supporting multiple platforms.

Below is a sequence of images showing the Angry Ninja game from Cartoonsmart running on the Kindle Fire.


Cocos2d-x and Box2D using LevelHelper


Coding a complicated physics game without the right tools is tedious and slow.  Fortunately there is a tool that makes this work easy and fast so you can concentrate on creating a great game.

LevelHelper along with SpriteHelper are excellent tools for creating sprite sheets and generating usable physics code.  The author of this tool, Vladu Bogdan, is constantly improving the tools allowing you to easily create levels for your games complete with physics working with your sprite sheets taken from SpriteHelper.  The tool allows instant testing of the physics using the built in Scene Tester.

The software only works for the MAC and it is well worth purchasing a MAC just for this tool as it will save weeks and months of work for your development project.  The author supports cocos2d-x which can be run on several platforms.

The software can be purchased in the Apple App store, more information can be found at

Ray Wenderlich has excellent tutorials for cocos2d and Vladu has contributed an excellent tutorial series using LevelHelper and SpriteHelper.

Part 1

Part 2:

Part 3:

Part 4:

The final code for this tutorial series has been converted to cocos2d-x and will be posted soon.  Using cocos2d-x and Marmalade SDK it was an easy task to get the finished game onto the Kindle Fire.


Cocos2d to Cocos2d-x

The difference between the Objective-C and C++ code can be viewed here and can be used as an aid to converting between the languages for cocos2d to cocos2d-x conversions.


Radial Gravity with Cocos2d-x


A simple but interesting demo of using Cocos2d with Box2D physics can be found at

The Objective-C code using Cocos2d can be found at that link.

Converting it to Cocos2d-x and C++ was very easy and provides another good example of porting existing Cocos2d code to various platforms using C++.

Most of the code on this blog can also be deployed using the native code from Cocos2d-x or Marmalade SDK  for those that are targeting multiple platforms.  Just look for the include “mkb” file.


The only part about this post that was tricky was doing the Box2d debug draw but luckily the code is included in the Box2d test code in Cocos2d-x.  The extra files required were GLES-Render.cpp and GLES-Render.h and they are included.

The source code can be found at:

You will need to have the cocos2d-x development environment.  Load the cocos2d-win32.vc2008.sln (for example) and just add the  RadialGravity.win32.vcproj to the solution.

The code has been updated and tested with cocos2d-1.01-x-0.11.0 release that includes and updated version of Box2D.

Tweejump–Objective C to C++ and Cocos2D-x


A good way of learning Cocos2d-x is to convert an existing Cocos2d game.  One that we chose was the tweeump game.  The code for this game is at:

Some discussion about the development is located on the Cocos2d-x forums at:

The main difficulty in doing this port was the the original tweejump located at was based on an older cocos2d.

The Objective C was that not difficult to port to C++ and the rules of translating Objective C to C++ posted here provided some guidance.

Keep an eye on the repository for the Tweejump as updates to the code will be made until it is a good solid example of a game using Cocos2D-x with C++.