0

我得到了这个 lil 文件

/* WaterBall API notification model by Makerimages*/
function WBNotification(x,y,icon,text)
{
this.background="/WBGraphics/WBNotification.png";
this.x=x;
this.y=y;
this.icon=icon;
this.text=text;






this.draw=function()
{

var canvas = document.createElement('canvas');
canvas.id="WBNotificationArea";
canvas.width=88;
canvas.height =43;
document.body.appendChild(canvas);
cvs=document.getElementById("WBNotificationArea");
var context=cvs.getContext();
context.drawImage(this.background,this.x,this.y);
}
 return this;
}

我像这样使用它

site=new waterContainer();
site.notifications[0]=new WBNotification(10,10,null,"hello there!");
site.notifications[0].draw()

一切正常,但是 this.draw() 说(在 chrome 的脚本阅读中)它不能调用 null 的方法 drawImage,我该如何解决?

4

1 回答 1

3

您需要将字符串传递"2d"getContext().

null如果提供的上下文类型不可用,该函数将返回。

于 2013-10-11T14:46:08.863 回答