Tuesday 8 May 2007

flash frame rate

I just made my first flash frame rate widget. I wanted to have a frame rate widget because I'll soon be experimenting some processor intensive stuff in flash. It took me about 10 mins to make because it's really simple.

here's how to make it:
1) create a new movieclip symbol and navigate to its timeline
2) create a dynamic text box for the number to update itself
3) add a new layer for actionscript and add the following:

var frameCounter:Number = 0;
var frameRate:Number = 0;
var currSecond:Number;
var prevSecond:Number = 0;

this.onEnterFrame = function()
{
frameCounter++;
currSecond = int(getTimer()/1000);
if(currSecond > prevSecond){
prevSecond = currSecond;
frameRate = frameCounter;
frameCounter=0;
}
}

4) add "frameRate" without quotes to the dynamic text box you created above under the "Var:" box in your properties window.
5) decorate as you please, by adding a background box and border and the word "fps" inside a static text box, etc

i guess the code is self explanatory if you're a programmer, but for the non-programmer who isn't interested to learn programming but is wondering how it works, basically what it does is count the number of frames that flash can update per second and update the number in the box every second. its that simple.

i also just realised that flash can go up to a maximum of 120 fps (upper limit set by macromedia). tt's pretty gd but not great like c++ graphic engines. so all you c++ fans out there don't come complaining to me that the frame rate sucks. It reasonably good and 60 fps already provides ultra smooth animation, though the more stuff you have on screen makes the frame rate dip quite abit. i've been using like 15-20 fps for a long long time so i think i should be trying to push the fps for future projects up.

one thing though is that i tried running the the flash swf on my computer in flash player and it runs at 120 fps-124fps.
but running it on my mozilla web browser runs the same swf at 60fps to 90 fps only. I suspect the dip in frame rate is due to the flash file being run from the browser so its slower. Its an operating system thing.

and finally here it is:

Get Adsense

Want to earn money like me? Get Google Adsense now by clicking this