这应该是一个快速的问题,希望能快速回答。 :)我正在使用box2d作为我正在做的侧卷轴项目。一切都很顺利,谢谢你的提问。 :D无论如何,我的角色需要不同大小的盒子用于边界。我认为这就像为身体添加一个新夹具一样简单,但它不起作用。它崩溃了,我明白了:
java:./ Box2D/Collision/b2Distance.h:103:const b2Vec2& b2DistanceProxy :: GetVertex(int32)const:断言`0< = index&& 指数< m_count'失败。
我不知道这意味着什么。这是我用来创建主体和灯具的代码:
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(level.character.position);
Body body = b2world.createBody(bodyDef);
level.character.body = body;
PolygonShape polygonShapeHead = new PolygonShape();
origin.x = level.character.circleBoundOrigin.x * 2.0f;
origin.y = level.character.circleBoundOrigin.y * 3.0f;
polygonShapeHead.setAsBox(level.character.circleBoundOrigin.x,
level.character.circleBoundOrigin.y, origin, 0);
FixtureDef fixtureDefHead = new FixtureDef();
fixtureDefHead.shape = polygonShapeHead;
fixtureDefHead.friction = level.character.friction.x;
body.createFixture(fixtureDefHead);
polygonShapeHead.dispose();
PolygonShape polygonShapeBod = new PolygonShape();
origin = level.character.rectBoundOrigin;
polygonShapeHead.setAsBox(level.character.rectBoundOrigin.x,
level.character.rectBoundOrigin.y, origin, 0);
FixtureDef fixtureDefBod = new FixtureDef();
fixtureDefBod.shape = polygonShapeBod;
fixtureDefBod.friction = level.character.friction.x;
body.createFixture(fixtureDefBod);
polygonShapeBod.dispose();
据我所知,我正在做好一切。那么为什么它不起作用?为什么会崩溃?我正在使用fixturedef。这可能是问题所在。谢谢!
答案 0 :(得分:2)
在world.step()期间添加/销毁obect时会发生这种情况。如果您正在动态添加/销毁对象,则需要对其进行排队,并确保在调用world.step()之前或之后进行更改。
本教程系列中对此进行了讨论。 http://youtu.be/ACQaU2Vr1ao?t=15m26s