我哪里错了?当我测试它时,例如如果我输入 abc 它会输出到画布 aaaaaaaabbbbbbccccccc

问题描述

function TextTool(){
//set an icon and a name for the object
this.icon = "assets/icons/texttool.jpg";
this.name = "texttool";

var x = 0;
var y = 0;
var startingX = 0;



this.event = function() {
    if(mouseX > 0 &&
        mouseX < canvas.width && 
        mouseY > 0 &&
        mouseY < canvas.height
    ) {
        x = mouseX;
        y = mouseY;
        startingX = x;
        return true;
        
    }
    return false;      
};


this.draw = function() {

    if(c.mouseClicked(this.event)) {
        if(keyIspressed) {
            if(keyCode === ENTER) {
                // Enter key is pressed
                console.log("enter");
                x = startingX;
                y += 15;
            }
            else {
                text(key,x,y);
                console.log('called');
                x += 20;
                
            }    
        } 
    }
    else {
        if(keyIspressed) {
            if(keyCode === ENTER) {
                // Enter key is pressed
                console.log("enter");
                x = startingX;
                y += 15;
            }
            else {
                text(key,y);
                console.log('called');
                x += 20;
                
            }    
        }
    }   
};

}

我正在尝试为我的应用创建一个文本工具。 我如何使它(输入和调用)只调用一次。在草图文件的绘制函数中仅调用 this.draw 函数。 我必须为此使用 p5.js 库,有人能告诉我为什么我按下 abc 时会输出 aaaabbbbcccc。 我使用 https://p5js.org/reference/#/p5/mouseClicked 作为 mouseClicked 函数的指南。 这是我第一次使用这种类型的函数,就像我创建的其他工具一样,我只需要使用 mousepressed 方法,现在看起来更容易了。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)