简体   繁体   English

我在以下代码中不断收到错误“canvasContext.fillRect”

[英]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.

相关问题 canvasContext.fillRect在Firefox中抛出NS_ERROR_FAILURE异常 - canvasContext.fillRect throws NS_ERROR_FAILURE exception in Firefox 我不断收到以下错误:“错误:找不到模块'./framer'” - I keep getting the following error: “Error: Cannot find module './framer'” 为什么在以下3行代码中出现JavaScript错误? - Why am I getting a javascript error in the following 3 lines of code? 为什么在以下代码中出现未捕获的类型错误? - Why am I getting an uncaught type error with the following code? 我仅在Chrome中不断收到以下错误:未捕获的TypeError:无法读取null的属性“值” - I keep getting the following error in Chrome only: Uncaught TypeError: Cannot read property 'value' of null 为什么我在此行代码中不断收到“意外令牌”错误? - Why I keep getting an “unexpected token” error on this line of code? 我不断收到错误“拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令 - I keep getting the error "Refused to execute inline event handler because it violates the following Content Security Policy directive 当我尝试在“node.js”中运行这行代码时,我收到以下错误 - When I try to run this line of code in “node.js”, I am getting the following error 为什么我没有得到包含以下代码的表格? - Why am I not getting a table with the following code? 不断收到脚本语法错误,代码不起作用 - Keep getting script syntax error, code not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM