1

如何制作 b2EdgeShape?制作一个简单的 b2EdgeShape。在其之上构建的简单样板 b2EdgeShape。

我的代码:

var bodyDef = new Box2D.Dynamics.b2BodyDef;
bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
bodyDef.position.SetV(new Box2D.Common.Math.b2Vec2(250/30, 250/30));

var fixtureDef = new Box2D.Dynamics.b2FixtureDef;
fixtureDef.shape = new Box2D.Collision.Shapes.b2EdgeShape(
  new Box2D.Common.Math.b2Vec2(2.5,0), 
  new Box2D.Common.Math.b2Vec2(2.5,2.5));

fixtureDef.density = 0;
fixtureDef.restitution = 0.0;
fixtureDef.friction = 0.0;

var body = world.CreateBody(bodyDef);
var fixture = body.CreateFixture(fixtureDef);
4

1 回答 1

2

还没有办法使用b2EdgeShape。它没有在 box2dweb 中完全实现。

您可以使用b2PolygonShape代替b2EdgeShape,如下所示:

fixDef.shape = new b2PolygonShape()
fixDef.shape.SetAsEdge(new b2Vec2(x1, y1), new b2Vec2(x2, y2))
于 2015-07-14T07:09:43.847 回答