【问题标题】:Uncaught TypeError: ctx.fillText is not a function (Javascript Canvas)未捕获的 TypeError:ctx.fillText 不是函数(Javascript Canvas)
【发布时间】:2016-05-16 22:25:41
【问题描述】:
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 上检查元素时,它给了我这个奇怪的错误:Uncaught TypeError: ctx.fillText is not a function有什么想法会发生什么吗?

【问题讨论】:

    标签: javascript canvas typeerror


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-26
      • 1970-01-01
      • 2020-07-04
      • 2019-02-20
      • 1970-01-01
      相关资源
      最近更新 更多