kripken / box2d.js

Port of Box2D to JavaScript using Emscripten
1.32k stars 198 forks source link

Error while trying to destroy body #52

Closed manideepabc closed 10 years ago

manideepabc commented 10 years ago

var embox2dTest_joints = function() { //constructor }

embox2dTest_joints.prototype.setNiceViewCenter = function() { //called once when the user changes to this test from another test PTM = 30; setViewCenterWorld( new b2Vec2(0,0), true ); } embox2dTest_joints.prototype.setup = function() { //set up the Box2D scene here - the world is already created //setting up the base

body=new b2BodyDef(); body.set_position(new b2Vec2(0,0)); body.set_angle(0); body.set_type(b2_staticBody); ground=world.CreateBody(body); shape=new b2PolygonShape(); shape.SetAsBox(25,0.25); fixture=new b2FixtureDef(); fixture.set_shape(shape); fixture.set_density(10.0); fixture.set_restitution(0.5); ground.CreateFixture(fixture); //setting up body1 body=new b2BodyDef(); body.set_position(new b2Vec2(-15,5)); body.set_angle(-Math.PI/6); body.set_type(b2_dynamicBody); body1=world.CreateBody(body); shape=new b2CircleShape(); shape.set_m_radius(1.5); fixture=new b2FixtureDef(); fixture.set_shape(shape); fixture.set_density(5.0); fixture.set_restitution(0.5); body1.CreateFixture(fixture); } embox2dTest_joints.prototype.step = function() { //this function will be called at the beginning of every time step if(body1.GetPosition().get_x()-1.5>=20) { world.DestroyBody(body1); } } In the above code Iam trying to destroy the body if it exceeds the limits(x-cordinate>20).But I was getting an error: Uncaught # box2d.js :1 please help me regarding this issue.