unbind function in HTML5 Canvas

后端 未结 1 1905
礼貌的吻别
礼貌的吻别 2021-01-29 12:45

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. Pleas

相关标签:
1条回答
  • 2021-01-29 13:14

    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:

        function redraw() {
            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 over
               console.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.

    0 讨论(0)
提交回复
热议问题