HTML5 Canvas中的解除绑定功能 [英] unbind function in HTML5 Canvas

查看:326
本文介绍了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.

谢谢

Devesh

推荐答案

选择矩形然后选择橡皮擦后,您看到另一个矩形的原因是:

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数组的所有工具。因此,一旦你添加了rect然后橡皮擦,那么rect仍然存在。

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中的解除绑定功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆