1

I have set my setInterval to 10 seconds. And it all working fine in my game, it count down from 10 seconds and change scene when it hit 0.

The problem is that I really would need to show milliseconds to and I cant understand how I will add it to the counter... It shouldnt be hard at all but I really cant figure it out.

Here is the script:

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

}
countdownInterval = setInterval(countdown,1000);

1 Answers1

0

You probably need a Date() object which will report time deltas in milliseconds. Using setTimout to increment a timer is likely to have a number of problems.

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);
meawoppl
  • 2,714
  • 1
  • 23
  • 30