Radial Gravity with Cocos2d-x

 

A simple but interesting demo of using Cocos2d with Box2D physics can be found at http://www.vellios.com/2010/06/06/box2d-and-radial-gravity-code/

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.

(see http://www.madewithmarmalade.com)

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: http://www.neonchalk.com/files/RadialGravity.zip

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.

4 thoughts on “Radial Gravity with Cocos2d-x

  1. admin Post author

    Just updated it so you can get the file, also updated the code to work with the latest cocos2d-x which uses a newer version of Box2D.

  2. Pingback: Cocos2D-x官方教程:示例代码应用中国 | 应用中国

Leave a Reply

Your email address will not be published. Required fields are marked *