I have created the following code on jsfiddle. The goal is to remove a box from the canvas after it has been clicked. What actually happens is that the grid is cleared and compl
Working Fiddle
Change createBox
to the following.
this.createBox = function( xpos, ypos )
{
this.context.beginPath();
this.context.rect( xpos, ypos, this.boxWidth, this.boxHeight );
this.context.fillStyle = '#444';
this.context.fill();
this.context.closePath();
};
Your not properly starting/ending paths, so the previous path isnt cleared when you redraw thus filling them all in again. Another way around it is to just use fillRect
instead.
The first step to create a path is calling the beginPath method. Internally, paths are stored as a list of sub-paths (lines, arcs, etc) which together form a shape. Every time this method is called, the list is reset and we can start drawing new shapes.
Further Reading