diff --git a/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js b/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js index f7653d850..5d9585477 100644 --- a/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js +++ b/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2Body.js @@ -82,6 +82,7 @@ function b2Body(ptr) { this.buffer = new DataView(Module.HEAPU8.buffer, ptr); this.ptr = ptr; this.fixtures = []; + this.world = null; } b2Body.prototype.ApplyAngularImpulse = function(impulse, wake) { @@ -110,7 +111,7 @@ b2Body.prototype.CreateFixtureFromDef = function(fixtureDef) { fixture._SetPtr(fixtureDef.shape._CreateFixture(this, fixtureDef)); fixture.body = this; b2World._Push(fixture, this.fixtures); - world.fixturesLookup[fixture.ptr] = fixture; + this.world.fixturesLookup[fixture.ptr] = fixture; return fixture; }; @@ -184,6 +185,10 @@ b2Body.prototype.GetUserData = function() { return this.buffer.getUint32(b2Body_userData_offset, true); }; +b2Body.prototype.GetWorld = function() { + return this.world; +}; + b2Body.prototype.GetWorldCenter = function() { b2Body_GetWorldCenter(this.ptr, _vec2Buf.byteOffset); var result = new Float32Array(_vec2Buf.buffer, _vec2Buf.byteOffset, _vec2Buf.length); diff --git a/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2World.js b/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2World.js index 5d1fc9a98..8597034bf 100644 --- a/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2World.js +++ b/liquidfun/Box2D/lfjs/jsBindings/Dynamics/b2World.js @@ -133,6 +133,7 @@ b2World.prototype.CreateBody = function(bodyDef) { bodyDef.linearVelocity.y, bodyDef.position.x, bodyDef.position.y, bodyDef.type, bodyDef.userData)); b2World._Push(body, this.bodies); + body.world = this; this.bodiesLookup[body.ptr] = body; return body; };