场景设置:
#canvas1{
position:absolute;
bottom:0;
left:0;
z-index:1;
}
#canvas2{
position:absolute;
bottom:0;
left:0;
z-index:0;
}
画布获取:
can1=document.getElementById("canvas1");
ctx1=can1.getContext('2d');/* 绘制 2d 场景 */
大鱼设置:
this.x =canWidth * 0.5;
this.y =canHeight * 0.5;
ctx1.drawImage(this.bigEye, -this.bigEye * 0.5, -this.bigEye * 0.5);
ctx1.drawImage(this.bigBody, -this.bigBody * 0.5, -this.bigBody * 0.5);
ctx1.drawImage(this.bigTail, -this.bigTail * 0.5 + 30, -this.bigTail * 0.5);
可是为什么老师写的ctx1.drawImage()大鱼是能够出来的呢。
ctx1.drawImage(this.bigEye, -this.bigEye * 0.5, -this.bigEye * 0.5);
写错了,应该是
ctx2.drawImage(this.bigEye, -this.bigEye.width * 0.5, -this.bigEye.height * 0.5);
draw()函数要在mian.js中调用