-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfps.as
33 lines (26 loc) · 1.04 KB
/
fps.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class fps{
static var currentFps=30;
static var timeinit:Date = new Date;
static var lasttime=timeinit.getMilliseconds();
static var timepassed:Number = 1;
static var TimePassed:Number = 1;
static function countDeltaTime(){
var time:Date = new Date;
//on each frame, figure out how much time has passed by comparing the milliseconds of the last frame to
//the milliseconds of the current frame
timepassed=((time.getMilliseconds()-lasttime)>=0)?(time.getMilliseconds()-lasttime):(1000+(time.getMilliseconds()-lasttime));
//convert the time passed between frames to frames per second. Round it to the nearest tenth.
currentFps = Math.round(10000/timepassed)/10;
//set last time for the next frame.
lasttime=time.getMilliseconds();
TimePassed = timepassed / 1000;
}
static function startFPSCounting (depth){
if (_root.fpsC == undefined)
_root.fpsC = _root.attachMovie('fpsCounter', 'fpsC', (depth == undefined)? -1 : depth);
_root.fpsC.onEnterFrame = function (){
countDeltaTime();
this.info.text = currentFps;
}
}
}