在JavaScript中从“Sprite”数组中绘制图像

时间:2015-12-01 19:38:16

标签: javascript arrays image sprite

所以我用JavaScript制作游戏,并且我试图将“精灵”放在数组中。

这是我的Sprite对象的样子

function Sprite(imgsrc)
{
 this.x = 0;
 this.y = 0;
 this.velocity_xr = 0;
 this.velocity_xl = 0;
 this.velocity_yu = 0;
 this.velocity_yd = 0;
 this.velocity_x = 0;
 this.velocity_y = 0;
 this.IMG = new Image();
 this.IMG.src = imgsrc;
 this.visible = false;
}

所以我做到了这一点:

var buttons = [];
var b = new Sprite("https://i.imgur.com/qDH38qs.png");
buttons.push(b):

然后尝试使用此行绘制它,但没有成功。

ctx.drawImage(bullets[0].IMG,300,300);

然而,这有效:

ctx.drawImage(b.IMG,300,300);

我错过了什么?

0 个答案:

没有答案