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?

Magnilex
  • 11,584
  • 9
  • 62
  • 84
chamberlainpi
  • 4,854
  • 8
  • 32
  • 63
  • Regarding b2DebugDraw, I'm starting to think it's left to us to implement (based on [this](https://github.com/google/liquidfun/blob/4c49f1b3b17ce40fa1a29671789ba580897a0926/liquidfun/Box2D/Box2D/Documentation/Programmers-Guide/Chapter13_Debug_Drawing.md)). But the documentation makes no mention of b2ContactListener being deprecated (at least that I could find). If you have any more clues, please share, as I am trying to solve the same mystery. – snapfractalpop Nov 23 '14 at 18:16
  • I (finally) added the newly created tag to your question, and removed the frameworks tag, which seemed least relevant. – Magnilex May 26 '15 at 20:44
  • @Magnilex - Excellent! It's never too late :) thanks a bunch for doing that. – chamberlainpi May 26 '15 at 21:08

1 Answers1

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.

rossi
  • 118
  • 2
  • 7