[cocos2d v.3] How to enable box2d?

Hello everyone,

I have tried to enable box2d and disable chimpmunk. On the CMakeLists.txt I changed:

option(USE_CHIPMUNK "Use chipmunk for physics library" OFF)
option(USE_BOX2D "Use box2d for physics library" ON)

But when parsing cmake I get:

Using chipmunk ...

And during compilcation “undefined reference” to box2d calls rises, as it was not linked.

I tried to setup flags by force, like this:

set(USE_BOX2D true)
set(USE_CHIPMUNK false)

But in that case I get “there is no such file or directory chipmunk.h”.

Can anyone give me a hint how I can enable and link box2d ?

1 Like

Here is a way to add box2d (on Visual Studio):

  1. Open file CMakeLists.txt. At line 162 add "“box2d”
  2. FILE -> Add -> Existing Project:
    choose: …cocos2d\external\Box2D\proj.win32\Box2D.vcxproj
  3. Right Click on Project -> Project Dependencies, tick Box2D
  4. Right Click on Project -> References => Add New References, tick on Box2D -> ok
  5. save solution (ctrl s)
  6. check: open file proj.win32\YouProject.vcxproj, if it have “Box2D” then this is ok and you can now use box2d:

include “Box2D/Box2D.h”;
USING_NS_CC;

what you saying that if i want to use box2d its by default disabled ? …
why not to add into the cocos console option to choose between the 2

yup… thats a gud idea… :smile:

but i am sure there is a reason for the default integration of chipmunk.
But @Meir_yanovich has a valid approach i believe.

can anyone explain it to us. ?

I downloaded cocos2d-x v.3.1.1. At CMakeLists.txt I added:

set(USE_CHIPMUNK false)
set(USE_BOX2D true)

and also add “box2d” to

target_link_libraries(${APP_NAME}
  spine
  cocostudio
  cocosbuilder
  extensions
  audio
  cocos2d
  box2d
  )

Then everything works fine.

But with v.3.2 I still have problems.

Thanks @tieudaotu for your solution but I have Linux and no MSVS.

1 Like

can’t we just switch the OFF to ON for Box2d and the reverse for Chipmunk
in the CMakeLists.txt file ?

to use it… ?
also can we use both physics engine at the same time… ??

@slackmoehrle could you help us. ?

@pabitrapadhy

As I wrote before

option(USE_CHIPMUNK "Use chipmunk for physics library" OFF)
option(USE_BOX2D "Use box2d for physics library" ON)

has no effect.

You cannot use both physics engines at the same time.

hmm… i see… :smile:

Let me have someone look at this.

Anyone figure this out? I’ve been struggling with it for a few days now as well.

I have someone looking at this to help.

@Woppix take a look at this: [cocos2d v.3] How to enable box2d?

I’m asking someone to answer this for us. I’ll post his reply.

If you need to disable chipmunk, you also need disable CC_USE_PHYSICS in base/ccConfig.h, because our engine use chipmunk for physics integration.

I don’t know why “Using chipmunk …” still shown, I will check that.

I have tested this, It works for me.
You need to change line 37, 38 and 50, 51 in CMakeLists.txt, and disable CC_USE_PHYSICS in base/ccConfig.h.
But if you use lua, you can not disable chipmunk, it has some problem with lua-binding, we are working no this…

In Xcode->cocos2d_libs.xcodeproj
add Below code in GCC_PREPROCESSOR_DEFINITION

COCOS2D_DEBUG=1 USE_FILE32API CC_ENABLE_CHIPMUNK_INTEGRATION=0
COCOS2D_DEBUG=1 USE_FILE32API CC_ENABLE_BOX2D_INTEGRATION=1

It is running well in my game…

I would like to ask you about your last statement. What is the current status of the using Box2d in cocos2d-x with lua? It is possible to disable Chipmunk and enable Box2d?

Does anyone have any links or tips on the differences between Box2d and Chipmunk? For a beginner, where do I start in terms of learning the differences between the two?

gives a good summary off the differences

Awesome thanks :smile: