0

我尝试使用 box2d 的 SetAsArray 函数对俄罗斯方块形状进行建模。但是这些形状没有正确地与其他物体碰撞,有时会掉下来,有时会潜入。方形或圆形没有问题。

    fixDef.shape.SetAsArray([
        new b2Vec2(-1,1.5),
        new b2Vec2(-1,-1.5),
        new b2Vec2(1,-1.5),
        new b2Vec2(1,-0.5),
        new b2Vec2(0,-0.5),
        new b2Vec2(0,1.5)],6
    ); // Tetris shape

    bodyDef.position.Set(7,0);
    var body=world.CreateBody(bodyDef);
    body.CreateFixture(fixDef);

我做了一个小提琴来展示效果:

http://jsfiddle.net/lavisrap/JrzPH/598/

4

1 回答 1

1

From the Box2D manual: "Polygon shapes are solid convex polygons. A polygon is convex when all line segments connecting two points in the interior do not cross any edge of the polygon." http://www.box2d.org/manual.html

于 2014-05-19T13:50:26.103 回答