0
考虑下面的代码绘制飞船图像:绘制图像
// Get a handle to the image object
var image = document.getElementById('spaceship');
// Draw the image at (0,350)
context.drawImage(image,0,350); - error on this line
// Scaling the image to half the original size
context.drawImage(image,0,400,100,25);
// Drawing part of the image
context.drawImage(image,0,0,60,50,0,420,60,50);
在这个脚本后,HTML有这样的代码:
<img src = "spaceship.png" id = "spaceship">
我使用与书中图像不同的图像,但大概是实际的图像并不重要(已经测试了图像本身)。第二行有错误:context.drawImage(image,0,350); - 未定义未捕获的引用错误上下文。
语境以前曾定义:
var context = canvas.getContext('2d');
而且它已经为许多其他形状,但在该行的错误工作。