javascriptbox2dphysics-enginebox2dwebliquidfun

Has b2DebugDraw and b2ContactListener been replaced in liquidfun.js?


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:

Are those deprecated / not fully implemented / forgotten?


Solution

  • 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.