最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
动态显示FPS值
时间:2022-07-02 17:19:34 编辑:袖梨 来源:一聚教程网
package{
import flash.display.Sprite
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.text.TextField;
public class FPSShow extends Sprite{
private var txt:TextField;
private var count:int=0
public function FPSShow(){
init()
}
private function init(){
txt=new TextField();//创建文本实例
txt.textColor=0xff0000;//设置文本颜色
addChild(txt)//加载这个文本
var myTimer:Timer = new Timer(1000);//Timer类挺好使,类似于setInterval,参数是循环间隔时间,单位是毫秒
myTimer.addEventListener("timer", timerHandler);//注册事件
this.addEventListener("enterFrame",countHandler)//注册事件,这里相当于2.0的onEnterFrame
myTimer.start();//Timer实例需要start来进行启动
}
private function timerHandler(event:TimerEvent){//Timer实例调用的方法
txt.text="FPS:"+count
count=0//每隔1秒进行清零
}
private function countHandler(event:Event){//真循环调用的方法
count++//数值递加
}
}
}
import flash.display.Sprite
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.text.TextField;
public class FPSShow extends Sprite{
private var txt:TextField;
private var count:int=0
public function FPSShow(){
init()
}
private function init(){
txt=new TextField();//创建文本实例
txt.textColor=0xff0000;//设置文本颜色
addChild(txt)//加载这个文本
var myTimer:Timer = new Timer(1000);//Timer类挺好使,类似于setInterval,参数是循环间隔时间,单位是毫秒
myTimer.addEventListener("timer", timerHandler);//注册事件
this.addEventListener("enterFrame",countHandler)//注册事件,这里相当于2.0的onEnterFrame
myTimer.start();//Timer实例需要start来进行启动
}
private function timerHandler(event:TimerEvent){//Timer实例调用的方法
txt.text="FPS:"+count
count=0//每隔1秒进行清零
}
private function countHandler(event:Event){//真循环调用的方法
count++//数值递加
}
}
}
相关文章
- 柴犬币进军医疗领域,5000美元牙科账单用迷因币支付 07-13
- 道家经典名句解释162句 07-13
- 魔兽世界永恒长夜护腿在哪里刷-永恒长夜护腿刷取介绍 07-13
- 狗狗币能涨到1美元吗?DOGE创始人这样看 07-13
- ps怎么把黑白照片变成彩色?ps把儿童黑白照变彩色教程 07-13
- 关于命运的经典句子78句 07-13