Gael.D
Gael.D

Reputation: 500

Flash Game : getTimer unaccurate

I'm working on the game. The gameplay is based on a really small time lapse (you have only 5 secondes to do an action). My timer works great in Flash Player, i DO have 5 secondes. In a web browser (firefox, safari ..) the 5 seconds timer is now 8 seconds.

How to solve this ? Here is my code where i display the time:

private function updateTimer(e:TimerEvent) 
{
    if (this.timer.currentCount < 500) 
    {
         var centiemes:int = 100 - Math.floor(this.timer.currentCount) % 100;
         var secondes:int = 4 - Math.floor(this.timer.currentCount / 100) % 60;

         this.txtTemps.text = ToolBox.zeroFill(secondes.toString(), 2) + ":" +  ToolBox.zeroFill(centiemes.toString(), 2);
    }
    else 
    {
          this.txtTemps.text = "00:00";
          this.timer.stop();;
     }
 }

Thanks you !

Upvotes: 0

Views: 564

Answers (1)

Alan Klement
Alan Klement

Reputation: 1218

Yes Timer & setInterval are not accurate.

To get accurate time, you can either work with calculating delta between frames & time or you can use the technique that the Audiotool team uses and work with an audio file. You can find more info here and here.

Upvotes: 3

Related Questions