unbind function in 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 中的取消绑定功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:HTML5 Canvas 中的取消绑定功能


基础教程推荐
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- Bokeh Div文本对齐 2022-01-01