3

I'm trying to replace my current Box2D library (box2dweb.js) with Google's LiquidFun library.

The major difference seems like they placed all the b2#ClassName# classes in the global scope instead of keeping them modular (in a Box2D.* namespace like box2dweb did).

BUT it also seems like they've omitted a few b2#ClassName#, two of which I was using from the Box2dWeb.js version:

  • b2DebugDraw, and;
  • b2ContactListener;

Are those deprecated / not fully implemented / forgotten?

4

1 回答 1

1

Simply define the listener as an object of functions, like so:

var listener =  {
    BeginContactBody: function(contact) {
      console.log(contact.GetFixtureA());
    },
    EndContactBody: function(contact) {
        console.log(contact.GetFixtureA());
    },
    PostSolve: function(contact, impulse) {

    },
    PreSolve: function(contact, oldManifold) {

    }
}
world.SetContactListener(listener);

looking at https://github.com/google/liquidfun/blob/master/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2World.js helped me solve this, so if you run into other c++ -> javascript translation issues, that's a good starting point.

于 2015-02-27T09:42:30.553 回答