我以等距遊戲開始,當畫出地面的所有部分時,畫布閃爍(不在IE中)。當我將fps設置爲20或更少時,閃爍停止。我該如何解決這個問題?有任何想法嗎?HTML5 Canvas在繪圖上閃爍
var camerax = 300, cameray = 100;
var fps = 60;
function draw() {
clearCanvas();
drawGround();
}
function drawGround() {
var img = new Image();
img.onload = function() {
var width = img.width;
var height = img.height;
for (var x = 0; x < 3; x++) {
for (var y = 3; y >= 0; y--) {
mx = (x-y)*height + camerax;
my = (x+y)*height/2 + cameray;
ctx.drawImage(img, mx, my);
}
}
}
img.src = "ground.png";
}
var loop = setInterval(function() {
update();
draw();
}, 1000/fps);