FPS trace
/**
* Copyright bobby1 ( http://wonderfl.net/user/bobby1 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jYs2
*/
// forked from bobby1's 2次ベジェ
package {
import net.hires.debug.Stats;
import flash.geom.Rectangle;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.utils.Timer;
import flash.text.TextField;
import flash.display.Graphics;
import flash.display.Shape;
import flash.events.Event;
import flash.geom.Point;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var time:Number = 0;
private var ave:Number = 60;
private var offset:int=0;
private function ef(e:Event):void {
var ratio:Number = 0.95;
var tmp:Number = new Date().time;
var fps:Number = ( 1/(0.001*( tmp - time )));
if(fps>120)return;
ave = ave*ratio + fps*(1-ratio);
time = tmp;
bmp.bitmapData.fillRect( new Rectangle(offset,0,1,100) , 0x00000000 );
bmp.bitmapData.setPixel32(offset,100-30,0x777777);
bmp.bitmapData.setPixel32(offset,100-60,0x777777);
bmp.bitmapData.setPixel32(offset,100-Math.round(stage.frameRate),0xff0000);
bmp.bitmapData.setPixel32(offset,100-Math.round(ave),0xff8000);
bmp.bitmapData.setPixel32(offset,100-Math.round(fps),0xffffff);
offset++;if(offset>100)offset=0;
}
private var tf:TextField = new TextField();
private function makeDebugTF():void{
tf.width = 200;
tf.height = 200;
tf.scaleX = tf.scaleY = 2;
tf.textColor = 0xffffffff;
}
private var bmp:Bitmap = new Bitmap( new BitmapData( 100,100,false, 0x0 ) );
private function makeDebugView():void{
bmp.scaleY = bmp.scaleX = 4;
stage.addChildAt(bmp,0);
}
public function FlashTest() {
makeDebugTF();
makeDebugView();
addEventListener(Event.EXIT_FRAME, ef);
stage.frameRate = 17;
ave = stage.frameRate;
addChild(new Stats());
}
}
}