Actionscript - FPS (as2.0 & as3.0)

AS2.0:
this.onEnterFrame =
function() {
if (this.lastTimer != undefined) {
var
timerDiff:Number = getTimer()-this.lastTimer;
var fps:Number =
int(10000/timerDiff)/10;
trace(fps);
}
this.lastTimer =
getTimer();
};


AS3.0:

import
flash.utils.getTimer;
import flash.display.Sprite;

this.addEventListener(Event.ENTER_FRAME,GetTimerExample);

function
GetTimerExample(e:Event):void {
if(this.lastTimer != undefined){

var timerDiff:Number = getTimer()-this.lastTimer;
var
fps:Number = int(10000/timerDiff)/10;
trace("fps="+fps);

};
this.lastTimer=getTimer()
}

沒有留言:

張貼留言