如何制作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);

最佳答案

尚无法使用b2EdgeShape。在box2dweb中尚未完全实现。

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

fixDef.shape = new b2PolygonShape()
fixDef.shape.SetAsEdge(new b2Vec2(x1, y1), new b2Vec2(x2, y2))

关于javascript - Box2DWeb b2EdgeShape,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26335389/

10-13 01:27