HTML5 Canvas 中的取消绑定功能

unbind function in HTML5 Canvas(HTML5 Canvas 中的取消绑定功能)
本文介绍了HTML5 Canvas 中的取消绑定功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 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 regarding same.

谢谢

开发

推荐答案

选择矩形然后橡皮擦后看到另一个矩形的原因如下:

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);
    }

您正在将每个单击的工具添加到 clickTool 数组.所以一旦你添加了矩形然后橡皮擦,矩形仍然存在.

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

然后当你循环时:

    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.

这篇关于HTML5 Canvas 中的取消绑定功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

how to remove this error quot;Response must contain an array at quot; . quot;.quot; while making dropdown(如何删除此错误quot;响应必须在quot;处包含数组。创建下拉菜单时(Q;))
Why is it necessary to use `document.createElementNS` when adding `svg` tags to an HTML document via JS?(为什么在通过JS为一个HTML文档添加`svg`标签时,需要使用`Document.createElementNS`?)
wkhtmltopdf print-media-type uses @media print ONLY and ignores the rest(Wkhtmltopdf print-media-type仅使用@media print,而忽略其余内容)
price depend on selection of radio input(价格取决于无线电输入的选择)
calculate price depend on selection without button(根据没有按钮的选择计算价格)
What should I consider before minifying HTML?(在缩小HTML之前,我应该考虑什么?)