What is the most accurate way to track time in AS3?

It seems like the timer is gaining a lot of errors over time, so I wonder what other solutions people came up with for a more accurate timer. Thank!

+3
source share
4 answers

Obviously, you can measure the delays fairly accurately, so I assume that you are trying to fire the event after the delay, and your resolution is not enough.

Yes, the Timer class is a little awful. But you can use another trick:

If you need a 2 ms delay (for example) just use a while loop:

var startTime:Number = getTimer();
while(getTimer() < startTime + 2) {
    // whee
}
doStuff();

This should be taken for granted that doStuffit will not be executed after only 2 ms.

, , , , . , , , . .

, .

+2

, , -. , Flash ( , -, , ):

  • .
  • (OS, Timer, Input, stuff).
  • .

, , , 20 FPS, 50 . 10 , 10 , 30 . 1 , 20 , , Enter Frame Drawing . sucky, , , Flash - , .

, -, , , - .

+1

, , , Flash, , :

  • . .
  • .
  • , (true audio black). .
  • .
  • , . , . , .

Flash Player ( ) , .

, , .

+1

AS2, AS3 .

, as2, , 100 , , . getTimer(), , , , . , 99% . , 100 .

, Timer AS3, , , .

, , , .

, , , getTimer 1000, 2002, 3002. 2 , , 4 , 2 , 1000 , . , , 2 + 2 = 4, , .

:   var delay: int = 1000;

var myTimer:Timer = new Timer(delay, 0);

function timerHandler($evt:TimerEvent){
    trace(getTimer());
}

myTimer.addEventListener(TimerEvent.TIMER, timerHandler);

myTimer.start();
trace(getTimer());

:

15011
16011
17011
18054
19054
20054
21054
22054
23057
24054
25054
26054
27054
28011
29011
30011
31011
...
135047
136194 <- big one here
137246 - and here
138167 -
139242 -
140173 -
141016 <- back
142018 <- normalized
143018
144018
145019
146018
147018

It is interesting to see this "normalization." Sometimes it turns off for 54 ms, and then switches to 27 ms, and then up to 18 ms, etc. And it stays there for a while until it normalizes around another value. But this value is not cumulative, but rather close to the base. i.e. the displacement does not continue to grow. You would see a cumulative difference if you repeatedly created an event for one use.

0
source

Source: https://habr.com/ru/post/1784654/


All Articles