跟着老师的代码敲的,也引用到了main中了,为什么大鱼出不来,求教了!

来源:2-7 大鱼绘制

Willie_Jiang

2017-02-24 15:20

var momObj = function() {

this.x;

this.y;

this.bigEye = new Image();

this.bigBody = new Image();

this.bigTail = new Image();

}


momObj.prototype.init = function() {

this.x = canWidth * 0.5;

this.y = canHeight * 0.5;

this.bigEye.src = "/img/bigEye0.png";

this.bigBody.src = "/img/bigSwim0.png";

this.bigTail.src = "/img/bigTail0.png";

}


momObj.prototype.draw = function() {

ctx1.drawImage(this.bigEye, this.x, this.y);

ctx1.drawImage(this.bigBody, this.x, this.y);

ctx1.drawImage(this.bigTail, this.x, this.y);

}


报错如下:mom.js:18 Uncaught DOMException: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state.


写回答 关注

3回答

  • DuoiLONG
    2017-02-25 19:03:13
    已采纳

    this.bigEye.src = "/img/bigEye0.png";

    this.bigBody.src = "/img/bigSwim0.png";

    this.bigTail.src = "/img/bigTail0.png";


    这个好像有问题,少
    加了. 吧

    你改成这样试试看

    this.bigEye.src = "./img/bigEye0.png";

    this.bigBody.src = "./img/bigSwim0.png";

    this.bigTail.src = "./img/bigTail0.png";


    Willie...

    非常感谢!我自己检查了几遍都没发现这个问题。再次感谢,朋友!

    2017-02-26 15:40:29

    共 1 条回复 >

  • 慕移动9181930
    2022-03-26 20:44:39

    同学您好,对的,就是您这种写法就能将下标和值同时取出来了!

  • 慕粉185119458
    2017-02-28 17:38:36

    看到下面的回答是把ctx1改成ctx2就可以了

    我试过了

    Willie... 回复慕粉1851...

    嗯嗯,我开始也试过,发现最后也不行

    2017-03-06 11:52:22

    共 2 条回复 >

HTML5小游戏---爱心鱼(上)

学做HTML5游戏,轻轻松松带你上手,适合刚入手游戏开发的同学

92353 学习 · 550 问题

查看课程

相似问题