计算帧每秒的游戏 [英] Calculating frames per second in a game

查看:131
本文介绍了计算帧每秒的游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是好的算法来计算帧每秒的游戏?我想它显示为一个数字在屏幕的角落。如果我只是看花了多长时间来渲染一帧的数量变化太快了。

What's a good algorithm for calculating frames per second in a game? I want to show it as a number in the corner of the screen. If I just look at how long it took to render the last frame the number changes too fast.

如果你的答案更新每个帧不收敛时,不同帧​​速率在增加VS减少。加分

Bonus points if your answer updates each frame and doesn't converge differently when the frame rate is increasing vs decreasing.

推荐答案

您需要一个平滑平均值,最简单的方法是采取目前的答案(时间绘制的最后一帧),并使用previous结合起来的回答。

You need a smoothed average, the easiest way is to take the current answer (the time to draw the last frame) and combine it with the previous answer.

// eg.
float smoothing = 0.9; // larger=more smoothing
measurement = (measurement * smoothing) + (current * (1.0-smoothing))

通过调整0.9 / 0.1的比例可以改变'时间常数' - 那就是如何快速地数响应变化。赞成老答案较大部分给出了一个更慢更流畅的变化,很大一部分有利于新的答案给出了一个快速变化的值。显然,这两个因素必须添加到一个!

By adjusting the 0.9 / 0.1 ratio you can change the 'time constant' - that is how quickly the number responds to changes. A larger fraction in favour of the old answer gives a slower smoother change, a large fraction in favour of the new answer gives a quicker changing value. Obviously the two factors must add to one!

这篇关于计算帧每秒的游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆