Box2d (box2dWeb-2.1.a.3.js) debug draw setup

A simple example of how to use debug draw in box2d. You need the lines above to your box2d setup. You also need some bodies to add to the box2d world to see the debug draw.
 //setup debug draw
    
    var debugDraw = new b2DebugDraw();
	debugDraw.SetSprite(document.getElementById("astroCanvas").getContext("2d"));
	debugDraw.SetDrawScale(30.0);
	debugDraw.SetFillAlpha(0.5);
	debugDraw.SetLineThickness(1.0);
	debugDraw.SetFlags(b2DebugDraw.e_shapeBit | b2DebugDraw.e_jointBit);

	world.SetDebugDraw(debugDraw);


 	window.setInterval(update, 1000 / 60);

 	function update() {
    	
	   world.DrawDebugData();

	}

Responses

0 Replies