Box2DWeb b2EdgeShape

时间:2014-10-13 08:05:23

标签: javascript box2d box2dweb

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

1 个答案:

答案 0 :(得分:2)

尚无法使用 b2EdgeShape 。它没有在box2dweb中完全实现。

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

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