home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / alex_trax.swf / scripts / __Packages / com / neodelight / std / FpsCounter.as < prev    next >
Encoding:
Text File  |  2007-10-01  |  1.3 KB  |  50 lines

  1. class com.neodelight.std.FpsCounter
  2. {
  3.    var mc;
  4.    var timestamp;
  5.    var fps;
  6.    var smoothing;
  7.    var display;
  8.    function FpsCounter(smoothing, x, y)
  9.    {
  10.       if(x == undefined)
  11.       {
  12.          x = 0;
  13.       }
  14.       if(y == undefined)
  15.       {
  16.          y = 0;
  17.       }
  18.       this.mc = _root.createEmptyMovieClip("fpsCounter",_root.getNextHighestDepth());
  19.       this.mc.timestamp = getTimer();
  20.       if(isNaN(smoothing))
  21.       {
  22.          smoothing = 0.9;
  23.       }
  24.       this.mc.smoothing = Math.min(1,Math.max(0,smoothing));
  25.       this.mc.createTextField("my_txt",1,x,y,30,20);
  26.       this.mc.my_txt.multiline = false;
  27.       this.mc.my_txt.wordWrap = false;
  28.       this.mc.my_txt.type = "dynamic";
  29.       this.mc.my_txt.variable = "display";
  30.       this.mc.my_txt.selectable = false;
  31.       this.mc.my_txt.border = true;
  32.       this.mc.my_txt.background = true;
  33.       this.mc.onEnterFrame = function()
  34.       {
  35.          var _loc2_ = getTimer();
  36.          var _loc3_ = 1000 / (_loc2_ - this.timestamp);
  37.          if(isNaN(this.fps))
  38.          {
  39.             this.fps = _loc3_;
  40.          }
  41.          else
  42.          {
  43.             this.fps = (1 - this.smoothing) * _loc3_ + this.smoothing * this.fps;
  44.          }
  45.          this.display = Math.round(this.fps * 10) * 0.1;
  46.          this.timestamp = _loc2_;
  47.       };
  48.    }
  49. }
  50.