Jump to content

- - - - -

Cocos2d-x + Box2d Breakout Updated

4: Adsense

Cocos2d-x releases since version 3 have broken compatibility with old tutorials. This can especially be a problem when you want to do something slightly non-standard from the point-of-view of Cocos2d-x.

If you want to use physics in a Cocos2d-x game the current standard way to do this is to use the integrated physics classes, which are Chipmunk-based by default and can use Box2d too in some hybrid way the details of which are not at all clear. However, in my case I want to use Box2d, period, Box2d in a non-integrated manner for transparency and in order to leverage the vast amount of code that you get to peruse and possibly use by writing to vanilla Box2d. When doing something like this it can be hard to know where to start given that any sample code you find will be broken.

For setting up a Box2d/Cocos2d-x project there was always this BreakOut implementation to Cocos2d-iphone by Ray Wenderlich, link, which is transliterated into Cocos2d-x here but to relatively ancient versions of both Box2D and Cocos2d-x. I’ve taken that code and updated it to Cocos2d-x version 3.2 and Box2d version 2.3.

Here is my updated version.

To use do the following:
  • Setup a cocos2d-x v3.2 project via the python script. This will give you Box2d v2.3 set up in your project without you having to do anything else.
  • Copy the source code in the above zip file into your project’s Classes directory.
  • Copy the image files the Ball.jpg, Block.jpg, and Paddle.jpg from here into your project’s Resources directory.
  • Build.
(You can copy over the music/sound files too. I have the relevant calls commented out in the code above)


Aug 16 2014 01:17 PM

I think you need to double check your tags for this post.

Aug 16 2014 01:23 PM

Yeah. it always does that ... I have my external blog hooked up to my gamedev journal for certain topic tags on my external blog posts. Those posts automagically show up here but the HTML is always screwed up.


Something needs to be fixed on the gamedev side (I think) but I don't think it is a feature that people use enough for them to care about.

Aug 16 2014 02:06 PM

Thank you for the quick fix! I am excited to hear more.

Note: GameDev.net moderates comments.