在方法setInterval中,时间值只会更改一次我想用checkLevel 的值来更改它
var time=checkLevel((;
//在的msec水平上布线的方法
setInterval(function (event) {
time = checkLevel();
if (!isLoser) {
//Leere die Fläche
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
//Neu durchführen
randomX = getRandomPosition(canvasWidth - fishSize);
randomY = getRandomPosition(canvasHeight - fishSize);
var randomFish = Math.floor(Math.random() * 11) + 1;
fish.src = 'images/fish' + randomFish + '.png';
}
}, time);
您可以创建一个递归函数来更改间隔,然后只需调用一次间隔即可启动它,然后该函数每次调用都会更改间隔。
var _timer;
function showFish(){
if (!isLoser) {
//Leere die Fläche
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
//Neu durchführen
randomX = getRandomPosition(canvasWidth - fishSize);
randomY = getRandomPosition(canvasHeight - fishSize);
var randomFish = Math.floor(Math.random() * 11) + 1;
fish.src = 'images/fish' + randomFish + '.png';
}
_timer = setTimeout(showFish, checkLevel());
}
_timer = setTimeout(showFish, checkLevel());