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 中的取消绑定功能


基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01