【发布时间】:2014-04-16 22:16:25
【问题描述】:
这应该是一个快速的问题,希望得到快速的回答。 :) 我正在将 box2d 用于我正在做的侧滚轮项目。一切顺利,谢谢提问。 :D 无论如何,我的角色需要不同大小的框用于边界。我认为这就像在身体上添加一个新的固定装置一样简单,但它不起作用。它崩溃了,我明白了:
java: ./Box2D/Collision/b2Distance.h:103: const b2Vec2& b2DistanceProxy::GetVertex(int32) const: Assertion `0
我不知道那是什么意思。这是我用来创建主体和固定装置的代码:
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。这可能是问题所在。谢谢!
【问题讨论】:
-
您知道错误发生在您提供给我们的代码中的哪一行吗?
-
不,很遗憾。唯一出现在控制台框中的是上面的消息。
-
我刚刚运行它,它工作。再次运行它,同样的消息。有时有效,有时无效。这是怎么回事。 :|
-
会不会是您的
setAsBox()设置的顶点不正确?比如宽度=5,高度=0。还是宽度=-2,高度=3? -
没有。 :/ 一切正常。奇怪的是,每 1/20 次尝试,它实际上会运行。它也按照我的需要运行,在正确的位置有盒子。这可能不是我的代码中的错误,而是构建错误吗?