• fps


    package com.ultizen.hmlt.utils
    {
    	import com.ultizen.hmltMiniGame.crystal.greensock.plugins.VolumePlugin;
    	
    	import flash.display.Sprite;
    	import flash.events.Event;
    	import flash.events.MouseEvent;
    	import flash.text.TextField;
    	import flash.text.TextFormat;
    	import flash.utils.Timer;
    	import flash.utils.getTimer;
    
    /**
     * 
     * @author jiading
     * 
     */
    public class FPS extends Sprite
    {
    	//--------------------------------------------------------------------------
    	//		Static
    	//--------------------------------------------------------------------------
    	
    	//--------------------------------------------------------------------------
    	//		Constructor
    	//--------------------------------------------------------------------------
    	public function FPS()
    	{
    		addEventListener(Event.ADDED_TO_STAGE,addToStagaHandler);	
    	}
    	//--------------------------------------------------------------------------
    	//		Variables
    	//--------------------------------------------------------------------------
    	private var text : TextField;
    	//--------------------------------------------------------------------------
    	//		Properties
    	//--------------------------------------------------------------------------
    	private var crtTime : uint;
    	private var prevTime : uint;
    	private var fps : uint;
    	private var isWorking : Boolean;
    	private var str : String;
    	//--------------------------------------------------------------------------
    	//		Public Methods
    	//--------------------------------------------------------------------------
    	
    	//--------------------------------------------------------------------------
    	//		Event Handler
    	//--------------------------------------------------------------------------
    	private function addToStagaHandler(event : Event):void
    	{
    		removeEventListener(Event.ADDED_TO_STAGE,addToStagaHandler);
    		isWorking = false;
    		initBg();
    		initText();
    		this.buttonMode = true;
    		this.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
    	}
    	
    	private function mouseDownHandler(event : MouseEvent):void
    	{
    		if(!isWorking)
    		{
    			isWorking = true;
    			startWork();
    		}
    		else
    		{
    			isWorking = false;
    			stopWork();
    		}
    	}
    	
    	private function efHandler(event : Event):void
    	{
    		crtTime = getTimer();
    		
    		if(crtTime - 1000 > prevTime)
    		{
    			prevTime = crtTime;
    			text.text = "FPS: "+ fps.toString();
    			fps = 0;
    		}
    		fps++;
    		
    	}
    	//--------------------------------------------------------------------------
    	//		Protected
    	//--------------------------------------------------------------------------
    	
    	//--------------------------------------------------------------------------
    	//		Privates
    	//--------------------------------------------------------------------------
    	private function initBg():void
    	{
    		this.graphics.beginFill(0x000000);
    		this.graphics.drawRect(0,0,50,20);
    		this.graphics.endFill();
    	}
    	
    	private function initText():void
    	{
    		text = new TextField();
    		text.width = 70;
    		text.height = 20;
    		text.selectable = false;
    		text.mouseEnabled = false;
    		text.textColor = 0xff0000;
    		text.text = "show fps";
    		addChild(text);
    	}
    	
    	private function startWork():void
    	{
    		addEventListener(Event.ENTER_FRAME,efHandler);
    	}
    	
    	private function stopWork():void
    	{
    		removeEventListener(Event.ENTER_FRAME,efHandler);
    		text.text = "show fps";
    	}
    	//--------------------------------------------------------------------------
    	//		Dispose
    	//--------------------------------------------------------------------------
    }
    	
    }
    
  • 相关阅读:
    【第3版emWin教程】第27章 emWin6.x支持的字体简介
    【第3版emWin教程】第26章 字符编码和点阵字体基础知识(重要)
    嵌入式新闻早班车-第13期
    《安富莱嵌入式周报》第221期:2021.07.12--2021.07.18
    嵌入式新闻早班车-第12期
    TI发布采样率12.8Gsps,带宽6GHz,12bit分辨率高速示波器参考设计
    【DSP教程】第36章 FIR滤波器的Matlab设计(含低通,高通,带通和带阻)
    嵌入式新闻早班车-第11期
    【DSP教程】第35章 FIR有限冲击响应滤波器设计
    【STM32F407&F429&H7的DSP教程】第34章 滤波器基础知识
  • 原文地址:https://www.cnblogs.com/JD85/p/1987120.html
Copyright © 2020-2023  润新知