zoukankan      html  css  js  c++  java
  • 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
    	//--------------------------------------------------------------------------
    }
    	
    }
    
  • 相关阅读:
    Interface Builder: What are the UIView's Layout iOS 6/7 Deltas for?
    关于自定义 UITableViewCell
    关于自定义 UITableViewCell
    UITableViewHeaderFooterView can't change custom background when loading from nib
    UITableViewHeaderFooterView can't change custom background when loading from nib
    xcode制作越狱后ipa安装文件
    xcode制作越狱后ipa安装文件
    supports-screensandroid
    Windows 08 R2_组策略
    Windows 08 R2_创建AD DS域服务(图文详解)
  • 原文地址:https://www.cnblogs.com/JD85/p/1987120.html
Copyright © 2011-2022 走看看