kripken / box2d.js

Port of Box2D to JavaScript using Emscripten
1.33k stars 196 forks source link

WebAssembly support, and new async API #85

Closed kripken closed 7 years ago

kripken commented 7 years ago

This adds support for wasm, there is an extra build with suffix .wasm.js. It's noticeably faster and smaller.

To support wasm, we need async startup. That means that instead of just using the code, we need to wait until it is ready, using something like this,

Box2D().then(function(Box2D) {
  ..you can use Box2D here..
});
..but you cannot use it here..

This is like the Promise stuff that is common in JS today, so hopefully it's not too confusing, but it is an API change. Ideas on how to make this transition easier for people?

Issues: the wasm build has js + a wasm file on the side. That has some downsides, see https://github.com/kripken/emscripten/issues/5104