简体   繁体   中英

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:

  • b2DebugDraw , and;
  • b2ContactListener ;

Are those deprecated / not fully implemented / forgotten?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM