从一个数组中绘制一个图像;雪碧“;在JavaScript中
所以我用JavaScript制作了一个游戏,我试图将我定义的“精灵”放在一个数组中 这就是我的精灵对象的样子从一个数组中绘制一个图像;雪碧“;在JavaScript中,javascript,arrays,image,sprite,Javascript,Arrays,Image,Sprite,所以我用JavaScript制作了一个游戏,我试图将我定义的“精灵”放在一个数组中 这就是我的精灵对象的样子 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.I
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]。IMG尝试按钮[0]。IMG。。。