gpt4 book ai didi

javascript - Actionscript 2 Setinterval向计时器添加毫秒

转载 作者:行者123 更新时间:2023-11-28 08:30:07 25 4
gpt4 key购买 nike

我已将 setInterval 设置为 10 秒。在我的游戏中这一切都运行良好,它从 10 秒开始倒计时,并在达到 0 时改变场景。

问题是我真的需要显示毫秒,但我不明白如何将它添加到计数器中......这根本不应该很难,但我真的无法弄清楚。

这是脚本:

timer = 10;
clearInterval(countdownInterval);
countdown = function(){
timer--;
if (timer ==0){
gotoAndPlay("Scene 1",2 );
}

}
countdownInterval = setInterval(countdown,1000);

最佳答案

您可能需要一个 Date() 对象,它将报告以毫秒为单位的时间增量。使用 setTimout 增加计时器可能会出现许多问题。

var startTime = +(new Date) + (10 * 1000);
var checkFinished = function() {
timeRemaining = startTime - (new Date);
if(timeRemaining <= 0) {
gotoAndPlay("Scene 1",2 );
} else {
setTimeout(checkFinished, 100)l
}
}
setTimeout(checkFinished, 0);

关于javascript - Actionscript 2 Setinterval向计时器添加毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21972299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com