Skip to content Skip to sidebar Skip to footer

Unbind Function In Html5 Canvas

I want to unbind function in HTML5 Canvas... Example: when I am selecting Brush after selecting option rectangle its creating Rectangle also when I am using brush. Please help me r

Solution 1:

The reason you are seeing another rectangle after selecting rectangle and then eraser is because of the following:

    function addClick(x, y, dragging) {
        clickX.push(x);
        clickY.push(y);
        clickDrag.push(dragging);
        hitColors.push(bgColor);
        clickTool.push(tool);
        toolSize.push(radius);
    }

You are adding every tool that is clicked to clickTool array. So once you add the rect then eraser, the rect is still there.

Then when you loop:

functionredraw() {
        context.width = canvas.width; // Clears the canvas
        context.lineJoin = "round";        

        for (var i = 0; i < clickX.length; i++) {
           // this will log rect then eraser over and overconsole.log(clickTool[i]);
        // ......
        }
    }

So you need to work out why you want to have an array of tools that have been selected, maybe you only need to have one at a time instead of holding on to them all.

Post a Comment for "Unbind Function In Html5 Canvas"