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.
相关文章