Follow the body in html5 and box2d canvas

I use the box2dweb physics engine, my question is that I have a body and I want to follow it, for example, the width of my canvas: height is 500 pixels: 500 pixels and the coordination of the body (700,200), so I can’t see make it visible on my canvas

+3
source share
1 answer

You should use the box2dweb debug drawing.

function debugDraw(){
    var debugDraw = new b2DebugDraw();
//replace canvas with your canvas id
    debugDraw.SetSprite(document.getElementById("canvas").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); // replace world with your box2dworld
}

Put this feature on your gametop.

0
source

All Articles