我正在尝试使用这个函数。在创建对象的函数内部。但它似乎没有工作。javascript函数中的这个函数
function enemy(x, y) {
this.x = x;
this.y = y;
this.width = 32;
this.height = 32;
this.img = new Image();
this.ready = false;
this.img.onload = function() {
this.ready = true;
}
this.img.src = "images/barney.png";
}
this.ready从未设置为true,我需要这样才能渲染图像。有任何想法吗?
该函数中的'this'是指图像。 'console.log(this)'来看看。 – zerkms
谢谢,是的,我有点意识到,但不知道该怎么办。 – Kar