【发布时间】:2016-02-13 14:58:53
【问题描述】:
我最近开始学习 libgdx,但遇到了 Box2D 的 CainShape 的问题。
我的第一个目标是简单地创建一个带有 ChainShape 的盒子。
为了实现这一点,我将四个 Vector2 添加到一个数组中并使用它们创建一个循环。
结果取决于阵列中的排列,要么是沙漏形的东西(左上角与右下角相连,右上角与左下角相连),要么是错误
表达式:b2DistanceSquared(v1, v2) > 0.005f * 0.005f
这是我目前使用的代码:
Vector2[] box = new Vector2[4];
box[1] = new Vector2(0 - bounds.getWidth() / 2 / Main.PPM, 0 - bounds.getHeight() / 2 / Main.PPM);
box[0] = new Vector2( bounds.getWidth() / 2 / Main.PPM, 0 - bounds.getHeight() / 2 / Main.PPM);
box[2] = new Vector2(0 - bounds.getWidth() / 2 / Main.PPM, bounds.getHeight() / 2 / Main.PPM);
box[3] = new Vector2( bounds.getWidth() / 2 / Main.PPM, bounds.getHeight() / 2 / Main.PPM);
ChainShape chainShape = new ChainShape();
chainShape.createLoop(box);
fdef.shape = chainShape;
fixture = body.createFixture(fdef);
我希望有人能告诉我我错过了什么。
提前致谢!
【问题讨论】: