1

我正在尝试让 box2d debugdaw 在 cocos2djs 中工作。以下代码对我来说只是正常运行游戏,没有任何错误或调试形状。我哪里错了?

var b2Vec2 = Box2D.Common.Math.b2Vec2
    , b2World = Box2D.Dynamics.b2World
    , b2BodyDef = Box2D.Dynamics.b2BodyDef
    , b2Body = Box2D.Dynamics.b2Body
    , b2FixtureDef = Box2D.Dynamics.b2FixtureDef
    , b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape
    , b2DebugDraw = Box2D.Dynamics.b2DebugDraw;

// Construct a world object, which will hold and simulate the rigid bodies.
this.world = new b2World(new b2Vec2(0, -10), true);
this.world.SetContinuousPhysics(true);

var debugDraw = new b2DebugDraw();
debugDraw.SetSprite(cc.renderContext);
debugDraw.SetDrawScale(PTM_RATIO);
debugDraw.SetFillAlpha(0.8);
debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
this.world.SetDebugDraw(debugDraw);

然后我添加了世界边界和物理实体。

提前致谢。赞恩

4

1 回答 1

0

您是否尝试过执行以下操作而不是使用 debugDraw?

var debugNode = new cc.PhysicsDebugNode(space); debugNode.visible = true; this.addChild(debugNode);

我知道这适用于 Chipmunk 集成,我不确定 box2d,但它应该可以工作。

于 2014-12-01T12:37:26.540 回答