Hub

Radial Gravity

Thumb_rg

Brief

A simple but interesting demo of using Cocos2d with Box2D physics

Description

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.

Comments

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.