Flash components we've made, display-related utils.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@161 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2007-02-28 22:50:05 +00:00
parent 6e7b1741ff
commit 8e791eb994
7 changed files with 1246 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
//
// $Id$
//
// Nenya library - tools for developing networked games
// Copyright (C) 2002-2007 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/nenya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.flash {
import flash.events.Event;
import flash.text.TextField;
import flash.utils.getTimer; // function import
public class FPSDisplay extends TextField
{
public function FPSDisplay (framesToTrack :int = 150)
{
background = true;
text = String(Number.MIN_VALUE);
height = textHeight + 4;
_framesToTrack = framesToTrack;
addEventListener(Event.ENTER_FRAME, handleEnterFrame);
}
protected function handleEnterFrame (event :Event) :void
{
var curStamp :Number = getTimer();
_frameStamps.push(curStamp);
if (_frameStamps.length > _framesToTrack) {
_frameStamps.shift(); // forget the oldest timestamps
}
var firstStamp :Number = Number(_frameStamps[0]);
var seconds :Number = (curStamp - firstStamp) / 1000;
// subtract one from the frames, since we're measuring the time
// elapsed over the frames (when there are two timestamps, that's
// the difference between 1 frame)
var frames :Number = _frameStamps.length - 1;
this.text = String(frames / seconds);
}
/** Timestamps of past ENTER_FRAME events. */
protected var _frameStamps :Array = [];
/** The number of running frames we track. */
protected var _framesToTrack :int;
}
}