Fighterlegend's Blog Just some blog that expresses myself and what I do!

3Sep/0910

How to create a Flash Performance Calculator in AS3

This is a simple AS3 performance calculator I created..

/*********************************************************\
|*Thanks for using Fighterlegends performance Calculator!*|
\*********************************************************/
var documentFPS = stage.frameRate;
var lastTime = getTimer();
var samples = new Array(30);
var frameCounter = 0;
stage.addEventListener(Event.ENTER_FRAME, update);
function update(event:Event) {
	var currentTime = getTimer();
	var timeDif = (currentTime-lastTime)/1000;
	lastTime = currentTime;
	var actualFPS = 1/timeDif;
	samples[frameCounter % 30] = actualFPS;
	frameCounter++;
	var averageFPS = 0;
	for (var i = 0; i < 30; i++) {
		averageFPS += samples[i];
	}
	averageFPS /= 30;
	var performance = Math.round(averageFPS/documentFPS *100);
	var lag = 100-performance;

	fps.text = Math.round(averageFPS) + " fps\n" + documentFPS + " target fps\n" + performance +
	"% performance\n" + lag + "% lag\n";
}

Just create this dynamic box on the stage:
Instance: fps
width: 140
height: 84

Hope you give me credit!

UPDATE:
I got a new, and better update of the script from WarKry on Kongregate!

About Fighterlegend

I am a young man looking into a future. I am interested in Technology, such as Robotics and computers. I like to BMX also, though I'm not very professional (only can do simple tricks) I find it amusing.
Comments (10) Trackbacks (0)
  1. Hi! I was surfing and found your blog post… nice! I love your blog. Smile Cheers! Sandra. R.

  2. Thanks =D

  3. Hello from Russia!
    Can I quote a post in your blog with the link to you?

  4. Yeah! I don’t mind! I’ll check out your blog!

    Hello from America!

  5. Thank’s for sharing this
    This is really interesting

  6. No problem!

  7. Nice template , what is the name of tamplate you used in your site

  8. I used the Lightword template by Andrei Luca

    Thanks for visiting my blog!

  9. Brilliant idea and it is duly

  10. Haha, I forgot to update this code..
    I made a new one that I’m going to post possibly later today.
    Thanks for visiting my thread!


Leave a comment


Click to Insert Smiley

Spam Protection by WP-SpamFree

No trackbacks yet.

5 visitors online now
5 guests, 0 members
Max visitors today: 5 at 08:16 pm GMT+5
This month: 5 at 07-30-2010 08:16 pm GMT+5
This year: 24 at 04-20-2010 06:01 pm GMT+5
All time: 24 at 04-20-2010 06:01 pm GMT+5