2

I'm trying to clear a Canvas.

I execute a setInterval function, who calls different "canvas" in any iteration.

After any execution, i call this function:

function deleteCanvas(){
    var canvas = document.getElementById("canvas");
    var context = canvas.getContext("2d");
    context.clearRect(0, 0, context.width,context.height);
    context.beginPath();
}

But no delete the canvas image.

Any idea?

Best regards,

Antonio
  • 51
  • 1
  • 1
  • 5

2 Answers2

2

According to this HTML5 Canvas Tutorial: http://www.html5canvastutorials.com/advanced/html5-clear-canvas/

You do not have to call beginPath(). Next to this, you should probably change context to canvas.

$("#clear").on('click', function () {
    context.clearRect(0, 0, canvas.width, canvas.height);
});

Example: http://jsfiddle.net/cwv0y6nh/

lt.kraken
  • 1,287
  • 3
  • 10
  • 27
1

Try to change context.width to canvas.width. The same for height.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Access Denied
  • 8,723
  • 4
  • 42
  • 72