游戏开发:如何限制FPS? [英] Game Development: How to limit FPS?

查看:185
本文介绍了游戏开发:如何限制FPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个游戏,我看到FPS算法不能正常工作(当他必须计算更多,他睡得更长...)所以,问题很简单:如何计算睡眠时间具有正确的FPS?

I'm writing a game, and I saw the FPS algorithm doesn't work correctly (when he have to calculate more, he sleeps longer...) So, the question is very simple: how to calculate the sleeptime for having correct FPS?

我知道更新游戏需要多长时间,以微秒为单位,当然是我想达到的FPS。

I know how long it took to update the game one frame in microseconds and of course the FPS I want to reach.

我搜索疯狂的一个简单的例子,但我找不到一个....

I'm searching crazy for a simple example, but I can't find one....

代码可能是Java ,C ++或伪....

The code may be in Java, C++ or pseudo....

推荐答案

每帧的微秒数为 1000000 / frames_per_second 。如果您知道您已经花费 elapsed_microseconds 计算,那么您需要睡眠的时间为:

The number of microseconds per frame is 1000000 / frames_per_second. If you know that you've spent elapsed_microseconds calculating, then the time that you need to sleep is:

(1000000 / frames_per_second) - elapsed_microseconds

这篇关于游戏开发:如何限制FPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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