AS3 FPS 需要自己也会,但这外国佬的代码简明,值得分享给大家。
2012-03-28 14:33
141 查看
package { //imports import flash.events.Event; import flash.utils.getTimer; import flash.display.MovieClip; public class FPSCalculator extends MovieClip { //variable to hold the current time private var currentTime:int = 0; public function FPSCalculator() { //add the enter frame listener, this is fired when the SWF updates to a new frame stage.addEventListener(Event.ENTER_FRAME, onFrameLoop); } private function onFrameLoop (evt:Event):void{ //for the sanity of the fellow developers, try to put each task into a seperate function. //this makes it infinitely easier to read for them and yourself on a large project or when you come back to and old one //since the getTimer() function returns the played time in milliseconds and we want FPSecond, we divide it into 1000 var fps:Number = (1000 / timeDifference); trace(fps); } //this is a get function so it can be referenced just like a variable, without the brackets on the end like a normal function private function get timeDifference ():int{ //the getTimer() function returns the total played time of the SWF in milliseconds var totalPlayedTime:int = getTimer(); //The difference in time from the previous frame to this frame will to calculated here var timeDifference:int = (totalPlayedTime - currentTime); //The currentTime is set to the total played time so it is ready for the next frame currentTime = getTimer(); //return the difference in time return timeDifference } } }
相关文章推荐
- 当我开发需要时,我经常去的一些网站。给大家分享。也算自己做个小笔记
- 给大家分享网站源码有12.9G需要的自己去下载吧
- 好多人都在网上找PPC的拨号上网程序,我来发个自己的写的代码给大家分享下
- 分享自己的PHP操作记录日志代码
- 分享一个小工具,提供源码,以便根据自己需要进行修改
- as3 代码分享 第一章 图片缩放
- 在C#winform中运行js代码,需要自己转换提供所需要的JS
- 【读书笔记】建造者模式代码完成与大家分享
- 冒泡排序法 自己写的 大家分享
- css初始化代码,根据自己需要定义
- 左右两个Select列表框交换数据的JS代码,上下左右都可以移动数据,还可以置顶、沉底,相信大家见到过,但觉得挺实用,与大家分享。
- b站的代码,自己备份需要修改
- 把自己搜集到的一些silverlight网站、第三方控件及开源代码与大家们分享
- 代码质量之三-----关键的代码需要单元测试和自己review及交叉review
- 自己搞的一个验证码类,与大家分享!
- 记录自己在centos虚拟机搭建简易git服务器的过程,分享给大家
- 把自己开发的网站前端开发框架和大家分享下
- 圣思源Java视频36节练习源码分享(自己的190+行代码对比老师的39行代码)
- 马上要过年了,老板突然想到要大家各自交一份“我的50个梦想”,自己用了40分钟左右给搞出来了,贴出来给大家分享一下
- 整洁干净的代码之道-自己翻译太烂请大家先别浪费时间看