ActionScript 3: measuring elapsed time between enterFrame events

I have an EnterFrame event, and I want to know the exact time between calls, so I can animate objects more smoothly when the computer cannot create the desired frame rate.

+3
source share
4 answers

To be more specific.

currentTime = getTimer();
diff = currentTime - prevTime;

prevTime = currentTime;//update for next go around

EDIT

getTimer requires you to import the package: flash.utils.getTimer;

+10
source

use getTimer ();

+3
source

Timer - * ENTER_FRAME.

var timer:Timer = new Timer(500, 0);
timer.addEventListener(TimerEvent.TIMER, timerHandler);
timer.start();

private function timerHandler(event:TimerEvent):void
{
    // do something

    // *EDIT* Thanks @Luke spotting this out (check comments)
    event.updateAfterEvent();

}

*) , , , script (- - ), . , , .

+1

others say getTimer is the best way to go ... but I wanted to suggest something else: if you want to make time-based animations that are updated based on frames, you can also try some of the larger ActionScript animation libraries, like caurina Tweener ... they just do it out of the box and provide other great features ...

Greetz

back2dos

+1
source

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


All Articles