我有了一个构造函数的原型雪碧......的drawImage不工作
function Sprite(img) {
for (var property in img) this[property] = image[property];
}
...这发生在一个Image对象,使得它的一个副本。现在我想提请雪碧使用的drawImage:
Sprite.prototype.draw = function(ctx, x, y) {
ctx.drawImage(this, x, y);
}
这给了我一个错误:
Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': No function was found that matched the signature provided.
然而
如果我用实际Image对象,否则完全相同的代码,即:
Sprite.prototype.draw = function(ctx, x, y) {
ctx.drawImage(img, x, y);
}
它的工作原理与它应该完全相同(img是Image对象的全局名称)。
这是Sprite原型的完整代码。我不明白是什么差异导致这种情况发生,因为我只将一个函数添加到Sprite中;画。
[drawImage只支持本地对象。](http://stackoverflow.com/questions/14934033/draw-preloaded-image-into-canvas)。 – OrionMelt 2014-09-30 00:27:19