它非常困惑我正在设计一个 2d 游戏,我使用此代码将图像绘制到画布上,警报方法返回 background.x = 0 !但是当我将 x 更改为 z 或任何字母时,它会返回数字 400 i !为什么 background.x 总是等于零???
var canvas = document.getElementById('game');
var context = canvas.getContext('2d');
function loadResources(){
background = new Image();
background.src = "11.jpg";
background.width = 128;
background.height = 128;
background.x = 400;
background.y = 450;
}
function drawimage(){
alert(background.x);
context.drawImage(background,background.x,background.y,background.width,background.height);
}
function gameLoop() {
drawimage();
}
loadResources();
setInterval(gameLoop, 1000/60);