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
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.