93

There are a few different ports of Box2D for JavaScript. Which one is the best?

  • Box2DJS - "converted from Box2DFlashAS3_1.4.3.1 in an automatic manner"

  • Box2Dflash 2.0 ported to JavaScript - "one big nasty hack that just happens to work"

  • box2dweb - "a port of Box2DFlash 2.1a to JavaScript. I developed an ActionScript 3 -to- JavaScript converter to generate the code"

  • HBehrens/box2d.js - "a JavaScript Version of Box2D 2.1a" (Added Nov 21, 2011)

  • kripken/box2d.js - "a direct port of the Box2D 2D physics engine to JavaScript, using Emscripten" (Added Sep 24, 2013)

Any ideas which version http://chrome.angrybirds.com/ uses, if any?

a paid nerd
  • 30,702
  • 30
  • 134
  • 179
  • 1
    It doesn't even have to be a Box2D port. For example, [Matter.js](http://brm.io/matter-js/) and [p2.js](https://github.com/schteppe/p2.js) both seem to be pretty solid. – Thomas Sep 07 '16 at 17:40
  • @Thomas I agree. But look at the time the question was asked. At that time I believe Matter.js and p2.js haven't come out yet. – newguy Apr 04 '17 at 17:31
  • 1
    Probably, but I think this question came up in Google... no harm trying to keep SO up to date with useful pointers for those who come after you :) – Thomas Apr 05 '17 at 06:43

6 Answers6

92

Note to readers!

This question was originally asked and answered in 2011, but I'll do my best to keep it up to date!

Here's what I've found:

  • kripken/box2d.js is a port of Box2D using Emscripten and works well and is fast. I have used this personally with great success.
  • planck.js is the newest port and is written from the ground-up in JavaScript
  • Box2DJS is a port of Box2DFlash 1.4.3.1. box2dweb is a port of version 2.1a.
  • Box2DJS works "as a CommonJS module without any modifications at all" [1]
  • Box2DJS "not up-to-date and you have to import a big amount of JavaScript files in every project" [2]
  • box2dweb is contained in a single file [2]
  • box2dweb is "a much newer port and has a lot fewer issues" than Box2DJS [3]. However, switching might introduce new issues [4].
  • Box2DJS depends on Prototype but box2dweb does not [5]
  • Seth Ladd has promoted box2dweb with examples on his blog [6]
  • Nobody seems to be using the third alternative.
  • There are also physics simulators not based on Box2D. Check out Matter.js and p2.js

There's also a similar discussion on gamedev.stackexchange.com.

I'd say that the winner is kripken/box2d.js.

a paid nerd
  • 30,702
  • 30
  • 134
  • 179
  • box2d is not as up to date as box2dweb. a lot of core classes are missing from the minified file. – dopatraman Jan 22 '13 at 20:55
  • 1
    I personally used box2dJS in one project porting my existing iOS box2D game. What I found with the version difference is that some code from iOS works doesn't work in the JS version and the dev halt. After that, I used half a week to change all the code to box2dweb and every thing work fine as same as my iOS box2d game. So the version difference matters a lot. – Makzan Aug 02 '13 at 09:01
  • the emscripten port is pretty cool, but the last time i used it i found it to be buggy (including random freezes), and very hard to debug, due to the nature of emscripten. – bunnyhero Apr 12 '15 at 19:04
  • 2
    @aPaidNerd is this still up to date? – Ken Sep 15 '15 at 09:21
  • 2
    A new Box2d-ported JS physics engine called planck was out recently, check it out: https://github.com/shakiba/planck.js – newguy Apr 04 '17 at 17:33
13

This question and its best answer are from 2011. One recent new option is box2.js, an Emscripten translation of the C++ code to Javascript. As of August 2013 it's more up-to-date than the other ports I've found, and the demos seem to work.

Nelson
  • 27,541
  • 5
  • 35
  • 31
8

LiquidFun (With JS Bindings)

LiquidFun is, at the time I'm posting this, the most recent port to JS. It has all the features of Box2D and liquid physics features. It's ported using emscripten, so performance is decent.

google/liquidfun

google/liquidfun/tree/master/liquidfun/Box2D/lfjs

DylanVann
  • 483
  • 5
  • 9
  • I'm recently came across this and it looks ideal for simulating water flowing through pipes into tanks and valves etc. it would be a good solution for a project I'm looking at. Are there any tutorial out there especially how to actually get the library into my javascript. Documentation seems a bit scarce – Bob Haslett Dec 03 '15 at 17:36
6

Probably the best place to keep up to date with Box2D JavaScript ports is the official forum: http://box2d.org/forum/viewforum.php?f=22

JSBox2D looks like a good start.

I would definitely have a look into Matter.js, which seems very well built and very quick. I'm going down this path. http://brm.io/matter-js

zoosrc
  • 515
  • 3
  • 6
  • 12
3

Box2d-html5 is also another box2d port including Google's LiquidFun) and active update.

cuixiping
  • 24,167
  • 8
  • 82
  • 93
0

Box2DWeb supports most of the API from the original C++ Box2D except chain shapes. :/

It is the most widely used Javascript Box2D. If you need the API documentation for Box2DWeb, check out Box2DFlash. http://www.box2dflash.org/docs/2.1a/reference/

Box2DWeb is auto generated from Box2DFlash using a compiler. So the API is the same.

I doubt Box2DWeb will get any update in the future anymore as Box2DFlash has shown no activities anymore. You can see the author's rational on why he decided not to write a direct Box2D --> Box2DWeb port.

https://code.google.com/p/box2dweb/wiki/Roadmap

Vennsoh
  • 4,853
  • 5
  • 26
  • 41
  • The next contender for Box2D so far is PhysicsJS. wellcaffeinated.net/PhysicsJS/ (my 2cents) – Vennsoh Jul 29 '14 at 01:20
  • Google has released a plugin, LiquidFun (Go google) during I/O 2014. You will need Box2D v2.3 to use it. It is pretty awesome. – Vennsoh Jul 29 '14 at 01:38