我正在嘗試使用這個函數。在創建對象的函數內部。但它似乎沒有工作。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