2010-11-12 85 views
3

我有这样一段代码(该sCtx是画布背景和按钮是在紧张的平局循环):画布drawImage返回错误

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); 
    sCtx.drawImage(theImg); 
} 

当我运行的代码(在Chrome中)我得到这个输出:

<img src=​"img/​btnStart.png">

Uncaught TypeError: Type error

有人能告诉我我做错了什么吗?我已经看了很多例子,看起来这应该起作用。

+0

我有同样的问题。尽管添加了x,y坐标,但错误仍然存​​在。我该怎么做 – 2011-08-14 07:28:05

回答

5

我相信你需要x/y坐标,以告诉画布背景绘制位置:

sCtx.drawImage(theImg,0,0); 
+0

现在我觉得很愚蠢。谢谢您的帮助。 :) – EToreo 2010-11-12 21:07:30