未捕获的类型错误:ctx.fillText 不是一个函数(Javascript Canvas)

Uncaught TypeError: ctx.fillText is not a function (Javascript Canvas)

本文关键字:一个 Canvas Javascript 函数 类型 错误 fillText ctx      更新时间:2023-09-26
var ctx = space.getContext("2d"); 
var FPS = 40;
var score = 0;
    function scoring(){
      ctx.font = "20px Helvetica";
      ctx.fillStyle = "#001e52";
      if(score<10){
        ctx.fillText(score, center.x+44.5, center.y+57);
      }
      if(score>=10 && score<=99){
        ctx.fillText(score, center.x+38.9, center.y+57);
      }
      if(score>=100 && score<=999){
        ctx.fillText(score, center.x+33, center.y+57);
      }
      if(score>=1000){
        score=0;
      }
    }
    setInterval(scoring, 1000/FPS);

上面的代码正在开发我完全按照演示制作的另一个画布游戏。现在我将其复制并粘贴到我的新游戏中,但它不起作用(我显然更改了坐标和所有内容以适应我的新游戏)。在Chrome上检查元素时,它给了我这个奇怪的错误:未捕获的类型错误:ctx.fillText不是一个函数 任何想法会发生什么?

我必须删除 fillText 函数的先前实例,以便它在画布上绘制分数。不知道为什么,但它奏效了。

我遇到了同样的问题。我看得更仔细了,它filltext(some arguments).问题是我用小T写的,而不是用camelCase写的。