[每次我运行应用程序并打开控制台时,此错误“ pong.js:25 Uncaught TypeError:canvasContext.fillRect在drawEverything(pong.js:25)都不起作用”,我一开始就会每秒出现那是因为我没有正确拼写“ fillRect”,但是我不知道为什么会这样,有什么想法吗?谢谢
var canvas
var canvasContext;
var ballX = 50;
window.onload = function() {
canvas = document.getElementById('gameCanvas');
//get context to draw on
canvasContext = canvas.getContext('2d');
setInterval(drawEverything, 1000);
}
function drawEverything() {
ballX = ballX + 20;
console.log(ballX);
canvasContext.fillStyle = 'black';
canvasContext.fillRect(0,0,canvas.width,canvas.height);
canvasContext.fillRect = 'white';
canvasContext.fillRect(225,210,200,200);
canvasContext.fillStyle = 'red';
canvasContext.fillRect(ballX, 200, 50, 25);
}
您正在使用字符串覆盖您的fillRect函数
canvasContext.fillRect = 'white';