gpt4 book ai didi

javascript - 在参数列表后缺少 ),即使我在指定位置添加了 )

转载 作者:行者123 更新时间:2023-11-30 18:28:15 26 4
gpt4 key购买 nike

在浏览器中查看我的网页时,我在以下功能上收到此控制台错误。

function drawStartButton(){
image.onload = function(){
context.drawImage(image, 260.5, 60);
image.on("mousdown", function(){
drawLevelOneElements();
}
});
image.src = "StartButton.png";
/** Now I need to add an event listener to the area of the canvas on
on which the button image is displayed, in order to 'listen' for
a click on the button */
var boundingBox = myGameCanvas.getBoundingClientRect();
//var mouseX = (mouse_event.clientX-boundingBox.left) * (myGameCanvas.width/boundingBox.width);
//var mouseY = (mouse_event.clientY-boundingBox.top) * (myGameCanvas.height/boundingBox.height);
boundingBox.onmousemove = function(e){
var mouseX = e.pageX - this.offsetLeft;
var mouseY = e.pageY - this.offsetTop;
var pixels = context.getImageData(mouseX, mouseY, 1, 1);
}

/** There maybe more than one pixel at this location so use a loop
to test whether any of the pixels have an alpha value greater than
0. With pixel data, 3 is alpha, so check data[3] and every fourth
element in data after that. */
//for (var i=3; i<pixels.data.length; i+=4;){
/** If a non- zero alpha is found, stop and return "true"- the click
was on a part of the canvas that has colour on it. */
// if(pixels.data[i]!=0) return true;
//}

/** If the function gets here, then the mouse click wasn't on a painted
part of the canvas. */
//return false;
/**myGameCanvas.getElementById("StartButton").onClick = function(e){
drawLevelOneElements();
} */

}

错误发生在从第二行开始的函数末尾。最初,我的那一行只是 }; 但在收到此错误后,我将其更改为 });

但是,当我重新加载页面时, Canvas 仍然是空白的,并且控制台提示同样的错误,即使我已经在指示的位置插入了 )

我查看了针对此错误的一些建议主题,但似乎没有一个主题表明我需要做什么才能使函数在 Canvas 上显示它们的含义。有人有什么建议吗?

最佳答案

image.onload = function(){
context.drawImage(image, 260.5, 60);
image.on("mousdown", function(){
drawLevelOneElements();
}
});

需要:

image.onload = function(){
context.drawImage(image, 260.5, 60);
image.on("mousdown", function(){
drawLevelOneElements();
});
};

注意最后的)

关于javascript - 在参数列表后缺少 ),即使我在指定位置添加了 ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10283741/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com