Box2D based Javascript 2D Physics Engine called Box2DJS

Box2D is responsible for inspiring many 2d physics engines including Motor2, Box2DFlashAS3 and others.  Box2D the original toolkit is a solid c++ physics engine that has many great examples and features including real collision.

Now it has inspired a pure Javascript version of Box2D called Box2Djs to (using prototype dependency) to implement many of the same demos using the same functionality.  So it appears Box2D if you want to find a baseline standard physics kit for 2D, it now has versions in many languages that might allow you to have 2d physics capabilities across many platforms.

Box2DJS is a JavaScript port of Box2D Physics Engine. To tell the truth, this is converted from Box2DFlashAS3_1.4.3.1 in an automatic manner. (The reason why not Box2DFlashAS3_2.0.0 based is simply because I overlooked the renewal.)


  • prototype.js
  • IECanvas (when you use a canvas tag to display the result of your physics simulation)


How to use

  1. Download a zip file and extract it.
  2. Copy js/ and lib/ directories from the extracted directory to your app directory.
  3. Copy script tags in the header part of index.html in the extacted directory to your html file where you want to simulate physics.

    Because this library does not have a lazy-loading system now, you should load all classes before starting your simulation. To make things worse, each library has a bit complicated dependency each other so that loading libraries in wrong order may cause a fatal error. To avoid such a trouble, it is strongly recommended to copy the header part of this file or `index.html’ including the downloaded zip file.

  4. Utilizing Box2D APIs, simulate the newton world as you like.

    The Box2DJS APIs are completely same as those of Box2DFlashAS3. Please refer information about it.

Also the speed of your javascript engine makes a big difference just like the AS2 AVM1 to the AS3 AVM2 virtual machines.  Chrome is much faster than FF3.

Video of Box2DJS in Chrome

Video of Box2DJS in FF3

Tags: , , , , , ,

  • Mr.doob

    I’ve been working with it for a month, I’m awaiting for my experiments to be released :S As soon as they get released I’ll bring an improvement of it to the table :)

  • drawk

    mrdoob, sweet I cannot wait to see what you can make with it. It is definitely still slower and more lethargic than as3 versions but definitely nice in Chrome and maybe possible of some cool creations.

  • Pingback: 2D Physics Engine called Box2DJS |