home *** CD-ROM | disk | FTP | other *** search
- package org.ascollada.utils
- {
- import flash.display.Shape;
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.text.TextField;
- import flash.text.TextFormat;
- import flash.utils.getTimer;
-
- public class FPS extends Sprite
- {
- public var secondTime:Number;
-
- public var frames:Number = 0;
-
- public var prevFrameTime:Number = getTimer();
-
- public var frameTime:Number;
-
- public var time:Number;
-
- public var fps:String = "...";
-
- public var anim:String = "";
-
- public var bar:Shape;
-
- public var tf:TextField;
-
- public var prevSecondTime:Number = getTimer();
-
- public function FPS()
- {
- super();
- this.bar = new Shape();
- addChild(this.bar);
- this.bar.x = 19;
- this.bar.y = 4;
- this.bar.graphics.beginFill(16711680,0.5);
- this.bar.graphics.lineStyle();
- this.bar.graphics.drawRect(0,0,1,15);
- this.bar.graphics.endFill();
- this.tf = new TextField();
- addChild(this.tf);
- this.tf.x = 20;
- this.tf.y = 5;
- this.tf.width = 300;
- this.tf.height = 500;
- this.tf.defaultTextFormat = new TextFormat("Arial",9,16777215);
- this.tf.alpha = 0.6;
- addEventListener(Event.ENTER_FRAME,this.enterFrameHandler);
- }
-
- private function enterFrameHandler(param1:Event) : void
- {
- this.time = getTimer();
- this.frameTime = this.time - this.prevFrameTime;
- this.secondTime = this.time - this.prevSecondTime;
- if(this.secondTime >= 1000)
- {
- this.fps = this.frames.toString();
- this.frames = 0;
- this.prevSecondTime = this.time;
- }
- else
- {
- ++this.frames;
- }
- this.bar.scaleX = this.frameTime;
- this.prevFrameTime = this.time;
- this.tf.text = this.fps + " FPS / " + this.frameTime + " MS" + this.anim;
- }
- }
- }
-
-