简体   繁体   English

Flash游戏:getTimer不准确

[英]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). 游戏玩法是基于很小的时间流逝(您只有5秒的时间来做一个动作)。 My timer works great in Flash Player, i DO have 5 secondes. 我的计时器在Flash Player中效果很好,我确实有5秒。 In a web browser (firefox, safari ..) the 5 seconds timer is now 8 seconds. 在网络浏览器(firefox,safari ..)中,5秒计时器现在为8秒。

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 ! 谢谢 !

Yes Timer & setInterval are not accurate. 是Timer和setInterval不正确。

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. 为了获得准确的时间,您可以计算帧与时间之间的增量,也可以使用Audiotool团队使用的技术来处理音频文件。 You can find more info here and here . 您可以在此处此处找到更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM