1

I am trying to get box2d debugdaw working in cocos2djs. The following code for me just runs the game normally without any errors or debug shapes. Where am I going wrong?

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);

Then I add the world borders and physics bodies.

Thanks in advance. Zain

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Zain
  • 85
  • 1
  • 7

1 Answers1

0

Have you tried doing the following instead of using debugDraw?

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

I know this works for Chipmunk integration, I'm not sure for box2d, but it should work.

Sebastián Vansteenkiste
  • 2,234
  • 1
  • 19
  • 29
  • ya i tried it, doesn't seem to work for box2d. I ended up moving to chipmunk, it seems easier for js. – Zain Dec 02 '14 at 13:22