使用方法:
package {
import flash.display.Sprite;
import advancedflex.core.FPSView;
public class TestFPS extends Sprite {
//把FPSView 添加到enterFrame事件里,这样才能查看帧率。
addEventListener("enterFrame", FPSView.instance.enterFrameHandler);
//得到帧率,这个属性可以被绑定。
trace(FPSView.instance.fps);
}
}
源码:
/////////////////////////////////////////////////////////////////////////////
//Copyright 2007 Advanced Flex Project http://code.google.com/p/advancedflex/.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/////////////////////////////////////////////////////////////////////////////
package advancedflex.core {
import flash.events.Event;
import flash.utils.getTimer;
/**
* 查看帧率。
*/
public class FPSView {
//instance
private static const $INSTANCE:FPSView = new FPSView();
/**
* 得到实例。
*
* @return instance 实例。
*/
public static function get instance():FPSView {
return $INSTANCE;
}
//first time
private var ft:int;
把
//second time
private var st:int;
[Bindable]
/**
* 帧率。
*/
public var fps:int;
/**
* EnterFrame Event Handler.你必须把它添加到DisplayObject才能查看帧率。
*/
public function enterFrameHandler(event:Event):void {
st = getTimer();
fps = Math.round(1000 / (st - ft));
ft = st;
}
}
}
本文链接:https://assnippets.blogspot.com/2008/01/as3_11.html转载请注明出处。
相关文章:
0评论:
发表评论