[英]I keep getting the error "canvasContext.fillRect" in this following code
Every time I run the app and open the console this error "pong.js:25 Uncaught TypeError: canvasContext.fillRect is not a function at drawEverything (pong.js:25)" keeps coming up every second, at first I thought it was because I didn't spell "fillRect" properly, but I cannot figure out why this is happening, any ideas?每次我运行应用程序并打开控制台时,这个错误“pong.js:25 Uncaught TypeError: canvasContext.fillRect is not a function at drawEverything (pong.js:25)”每秒都会出现,起初我以为是因为我没有正确拼写“fillRect”,但我无法弄清楚为什么会发生这种情况,有什么想法吗? Thanks谢谢
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';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.