【问题标题】:Box2D libgdx polygon shapeBox2D libgdx 多边形形状
【发布时间】:2014-11-23 17:56:47
【问题描述】:

这怎么能正常工作:

Vector2[] vertexArray = new Vector2[3];
vertexArray[0] = new Vector2(0f, 0f);
vertexArray[1] = new Vector2(1f, 1f);
vertexArray[2] = new Vector2(2f, 5f);

polygonShape.set(vertexArray);

这会产生运行时错误

Vector2[] vertexArray = new Vector2[3];
vertexArray[0] = new Vector2(0f, 0f);
vertexArray[1] = new Vector2(1f, 1f);
vertexArray[2] = new Vector2(2f, 2f);

polygonShape.set(vertexArray);

错误:

AL lib: (EE) alc_cleanup: 1 device not closed
Assertion failed!

Program: C:\Program Files\Java\jre1.8.0_25\bin\javaw.exe
File: /var/lib/jenkins/workspace/libgdx/extensions/gdx-box2d/gdx-box2d/jni/Box2D/Collision/Shapes/b2PolygonShape.cpp, Line 223

Expression: false

这没有任何意义。第一个代码工作正常并绘制了三角形,但第二个代码没有。有人可以解释一下我做错了什么...

【问题讨论】:

  • 这个错误是所有程序运行都会出现,还是一次性异常?
  • 你已经用过那个多边形了吗?
  • 代码有效的可能性是 50%,我唯一要改变的是坐标。例如,[(0,0), (1,1), (2,5)] 有效,但 [(0,0), (1,1), (2,3)] 无效。跨度>

标签: libgdx box2d


【解决方案1】:

顶点 (0,0)、(1,1)、(2,2) 都在一条直线上 - 它们不构成多边形。这会导致触发断言,如错误消息所示(b2PolygonShape.cpp,第 223 行)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 2023-03-27
    相关资源
    最近更新 更多