🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Cocos2d-x + Box2d Breakout Updated

Published August 16, 2014
Advertisement
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:

  1. 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.
  2. Copy the source code in the above zip file into your project's Classes directory.
  3. Copy the image files the Ball.jpg, Block.jpg, and Paddle.jpg from here into your project's Resources directory.
  4. Build.

(You can copy over the music/sound files too. I have the relevant calls commented out in the code above)

Source
1 likes 3 comments

Comments

Navyman

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

August 16, 2014 07:17 PM
jwezorek

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.

August 16, 2014 07:23 PM
Navyman

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

August 16, 2014 08:06 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement