/** * FPS * Crea un medidor de frames por segundo para ver el rendimiento de la película. * La clase no limpia sus recursos. Utilizar sólo en modo depuración. * * @author Dani Llops * @version 1.0 * * Date Started: 2007/09/16 * Last Modified: 2008/01/05 * */ /* Licensed under the MIT License Copyright (c) 2007 Dani Llops (http://llops.com/blog) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package com.llops.utils { import flash.display.*; import flash.events.*; import flash.text.*; import flash.utils.Timer; public class FPS extends Sprite { private var _txt:TextField; private var _fps:int = 0; public function FPS() { init(); } private function init():void { // Fondo var fondo:Shape = new Shape(); fondo.graphics.beginFill(0x006699, .5); fondo.graphics.drawRect(0, 0, 40, 18); fondo.graphics.endFill(); addChild(fondo); // Texto _txt = new TextField(); _txt.height = 16; _txt.width = 40; _txt.x = 5; _txt.defaultTextFormat = new TextFormat("Verdana", 10, 0XFFFFFF); _txt.text = _fps.toString(); addChild(_txt); // Timer var t:Timer = new Timer(1000); t.addEventListener(TimerEvent.TIMER, secundero); t.start(); // Eventos addEventListener(Event.ENTER_FRAME, updateFrame); } private function secundero(e:TimerEvent):void { // Muestra los FPS _txt.text = _fps.toString(); _fps = 0; } private function updateFrame(e:Event):void { _fps++; } } }