每次我运行应用程序并打开控制台时,此错误“ 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);
}
答案 0 :(得分:0)
您正在使用字符串覆盖您的fillRect函数
canvasContext.fillRect = 'white';