java - Dynamic body is null in Box2d -


i have 1 dynamic sprite , few static. dynamic body:

bodydef bodydef = new bodydef(); bodydef.type = bodytype.dynamicbody;  bodydef.position.set(180, 20); bodymonkey = world.createbody(bodydef); polygonshape abcbox = new polygonshape();  bodymonkey.setuserdata(monkey1); bodymonkey.setfixedrotation(true); abcbox.setasbox(10.0f, 10.0f); fixturedef fixturedef = new fixturedef(); fixturedef.shape = abcbox; fixturedef.density = 0.5f;  fixturedef.friction = 0.0f; fixturedef.restitution = 0.9f;  fixture fixture = bodymonkey.createfixture(fixturedef); abcbox.dispose(); bodymonkey.setlinearvelocity(new vector2(1f, 0.5f)); bodymonkey.setlineardamping(1.0f); 

i have implement contactlistener. class:

@override public void begincontact(contact contact) {     object =  contact.getfixturea().getbody().getuserdata();     object b = contact.getfixtureb().getbody().getuserdata();// null      gdx.app.log("1", ""+a);     gdx.app.log("2", ""+b);     if(a!=null&&b!=null) {         gdx.app.log("ok", "");         screen2dbox.restartgame();     } }  @override public void endcontact(contact contact) {     // todo auto-generated method stub  }  @override public void presolve(contact contact, manifold oldmanifold) {     // todo auto-generated method stub }  @override public void postsolve(contact contact, contactimpulse impulse) {     // todo auto-generated method stub } 

but object b alaways null (a no, b dynamic, saw in logs). have try use try, catch, overcome (in block - screen2dbox.restartgame();) had error contact can not null. don't know how solve? help.

static body:

bodydef bodydefplatform1 = new bodydef();      bodydefplatform1.type = bodytype.staticbody;      bodydefplatform1.position.set(50, 280);      bodyplatform1 = world.createbody(bodydefplatform1 );      polygonshape platformbox1 = new polygonshape();        bodyplatform1.setuserdata(platform);      platformbox1.setasbox(20.0f, 10.0f);      fixturedef fixturedefplatform1 = new fixturedef();      fixturedefplatform1.shape = platformbox1;      fixture fixtureplatform = bodyplatform1.createfixture( fixturedefplatform1);     platformbox1.dispose(); 

i check code, can't see error. maybe object monkey1 null.

bodymonkey.setuserdata(monkey1); //check if monkey1 null. 

note: have low reputacion, can't post comment.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -