Canvas drawImage returns error
I have this piece of code (The sCtx is a canvas context and the button is in a tight draw loop):
function Button(src, onClick)
{
this.loaded = false;
this.image = new Image();
this.image.src = src;
this.onClick = onClick;
}
Button.prototype.draw = function()
{
if(!this.image.complete)
return;
var theImg = this.image;
console.log(theImg);
开发者_StackOverflow社区 sCtx.drawImage(theImg);
}
When I run the code (in Chrome) I get this output:
<img src="img/btnStart.png">
Uncaught TypeError: Type error
Can someone tell me what I am doing wrong? I have looked at many examples and it seems like this should work.
I believe you need x/y coordinates in order to tell the canvas context where to draw:
sCtx.drawImage(theImg,0,0);
精彩评论