Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between JBox2D and libGDX Box2D

I have working on libGDX and use Box2D for simple 2D physic interactions inside my game. However, recently I have found the existence of a library called JBox2D.

Is there any difference between this two libraries? What the advantages of one from another?

I know they both are based on the Box2D library for c++ because of this:

The Box2D implementation in libgdx is a thin Java wrapper around the C++ engine.


JBox2d is a Java port of the C++ physics engines LiquidFun and Box2d.

But, what do they mean by port and wrapping? Is JBox2D more complete than Box2D? which one is faster?

I ask this because I want to know if change my project from one to another (in this case from Box2D to JBox2D) can affect or optimize the performance of my game.

like image 464
Alex Sifuentes Avatar asked Feb 10 '23 08:02

Alex Sifuentes


1 Answers

As MadProgrammer said, the libgdx box2d extension (gdx-box2d) is a JNI wrapper around the native box2d library. While the JBox2D library is completely written port in Java and doesn't rely on the native library. However, you might find it interesting to know that the gdx-box2d extension uses JBox2d behind the scenes when it is not possible to wrap the native library. Which is only the case for the GWT backend.

In most cases (specifically Android) it is faster to use the JNI wrapper instead of JBox2d (it is probably also faster on iOS because RoboVM needs to translate the JBox2D bytecode). Which is why the extension uses that on the those backends. Of course this depends on that actual scenario, so you should benchmark and compare it know the actual difference.

I haven't bench marked gdx-box2d vs JBox2d myself. But I can say from experience that the (3D physics) gdx-bullet JNI wrapper is much faster compared to the JBullet Java port.

Please note that the gdx-box2d includes the required libraries. It does not depend on any libraries on the platform that needs to be updated. You also don't need to worry about ensuring that the correct libraries are installed.

like image 153
Xoppa Avatar answered Feb 11 '23 20:02

Xoppa