绘制小白色矩形但不是图像为什么它是这样以及如何修复它。没有使用onload()
var imageReady = false;
img = new Image();
img.src = 'player.png';
img.onload = loaded();
function loaded() {
imageReady = true;
redraw();
}
function redraw() {
//ctx.fillStyle = "blue";
//ctx.fillRect(0, 0, 500, 500);
if (imageReady) {
ctx.fillStyle = "white";
ctx.fillRect(10,10,10,10);
ctx.drawImage(img, 5, 5);
}
}
你能分享更多的代码吗?我假设你在img的onload中改变了imageRead。正确? – wendelbsilva
添加更多代码 – Myrez