Apply color/images rather than using debugdraw

How do you use images or color without using debugdraw?
Box2D doesn't really deal with rendering anything. The debug draw is only there as a convenience to check where things are.
For real applications, you would use the GetPosition and GetAngle functions of b2Body to ask the physics engine where each body is, and then draw it at that location and angle in the same way you would draw anything else with the rendering framework you are using.
Note to myself 😀 simple canvas and fixing image position with scaling

Code: Select all

function update() {
    world.Step(1 / 60, 8, 3);
    world.DrawDebugData();
    world.ClearForces();
   
    applyImages();
}

function applyImages() {
    var b2Body = Box2D.Dynamics.b2Body;
    for (b = world.GetBodyList() ; b; b = b.GetNext()) {
        if (b.GetType() == b2Body.b2_dynamicBody) {
            var pos = b.GetPosition();
            context.save();
            //multiply to scaling value
            context.translate(pos.x * scale, +pos.y * scale);
            context.rotate(b.GetAngle());
            //fix issue of opposite position of image in canvas
            context.drawImage(pillImage, -scale, 0);
            context.restore();
        }
    }
}
You might want to see these two blogs:

http://www.codingowl.com/readblog.php?blogid=150
http://codingowl.com/readblog.php?blogid=134

Original thread: https://box2d.org/forum/viewtopic.php?t=9806