我正在尝试通过这样的代码创建一个多边形物理体:
final float halfWidth = pAreaShape.getWidthScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT;
final float halfHeight = pAreaShape.getHeightScaled() * 0.5f / PIXEL_TO_METER_RATIO_DEFAULT;
final float centerX = 0;
final float left = -halfWidth;
final float right = halfWidth;
final float top = -halfHeight + 9f / PIXEL_TO_METER_RATIO_DEFAULT;
final float bottom = halfHeight;
final PolygonShape shape1 = new PolygonShape();
final Vector2[] vertices = {
new Vector2(centerX, bottom),
new Vector2(left+8f/PIXEL_TO_METER_RATIO_DEFAULT, bottom-19f/PIXEL_TO_METER_RATIO_DEFAULT),
new Vector2(left+7f/PIXEL_TO_METER_RATIO_DEFAULT, bottom-23f/PIXEL_TO_METER_RATIO_DEFAULT),
new Vector2(left+10f/PIXEL_TO_METER_RATIO_DEFAULT, top+14f/PIXEL_TO_METER_RATIO_DEFAULT),
new Vector2(left+13f/PIXEL_TO_METER_RATIO_DEFAULT, top+8f/PIXEL_TO_METER_RATIO_DEFAULT),
new Vector2(right-14f/PIXEL_TO_METER_RATIO_DEFAULT, top+8f/PIXEL_TO_METER_RATIO_DEFAULT),
new Vector2(right-11f/PIXEL_TO_METER_RATIO_DEFAULT, top+14f/PIXEL_TO_METER_RATIO_DEFAULT),
new Vector2(right-9f/PIXEL_TO_METER_RATIO_DEFAULT, bottom-23f/PIXEL_TO_METER_RATIO_DEFAULT),
new Vector2(right-10f/PIXEL_TO_METER_RATIO_DEFAULT, bottom-19f/PIXEL_TO_METER_RATIO_DEFAULT)
};
Body body = PhysicsFactory.createPolygonBody(pPhysicsWorld, pAreaShape, vertices, pBodyType, pFixtureDef);
可变顶点包含此形状的顶点。
而且它不起作用 - 应用程序启动(显示黑屏和应用程序标题栏),然后退出而没有任何错误(LogCat 中没有崩溃对话框和错误)。
但是当我删除顶点数组的元素之一时,它工作正常。
我做错了什么?