我正在开发一个游戏导入程序,它可以读取XML文件并为每个物体创建box2d刚体。
例如:
<polygon vertexCount="3" density="0" friction="0.25" restitution="0.30000000000000004">
<vertice x="6.506500000000001" y="0.4345"/>
<vertice x="6.534970527648927" y="0.48385302734375"/>
<vertice x="6.478029472351075" y="0.48385302734375"/>
</polygon>
问题在于我现在遇到了多边形部分的导出器,我需要在添加顶点并设置它们的位置之前设置一个b2vec2数组。
int count = [[childnode attributeForName:@"vertexCount"] intValue];
b2Vec2 points[count];
但是 Box2d 希望 points[5] 是一个实际的字面数字(例如 points[5]),而不是一个变量 points[number]。当我使用变量 count 时,它输出的错误是:
Variable length array of non-POD element type 'b2Vec2'
我该如何解决这个问题?我尝试将它设为常量,但这也不起作用(而且对我没有帮助,因为我需要它是动态的)。