David Babayan David Babayan - 1 month ago 13
Javascript Question

canvas.lineCap and canvas.closePath not work together

This is my code:

canvas.lineCap = "round";
canvas.lineWidth = 15;
canvas.beginPath();
canvas.moveTo(100, 100);
canvas.lineTo(200, 100);
canvas.closePath();


If I delete
canvas.closePath()
then
canvas.lineCap
works otherwise that parameter
not work. So what is the problem?

Answer Source

Call

canvas.stroke();

Instead of

canvas.closePath();

canvas.closePath() would mean you want to draw a polygon, which I assume is not the case.