游戏开发:无论FPS如何,游戏开发者如何保持游戏速度?

发布于 2024-11-30 15:35:21 字数 167 浏览 1 评论 0原文

假设角色在游戏中跳跃需要一整秒,如果 FPS 为 10fps、30fps、100fps 等,游戏开发人员如何将跳跃时间保持在 1 秒? - 如果你明白我的意思,你会如何阻止游戏的 fps 基本上影响游戏速度。

我认为有某种方法可以做到这一点,所以我想知道它到底是什么?

谢谢, 亚历克斯!

Say like it took a whole second for a character to jump in a game, how would a game developer go about keeping that jump time to 1 second if the FPS is either 10fps, 30fps, 100fps etc? - If you get me, how would you stop a game's fps affecting the gameplay speed basically.

I presume there's a certain method of doing this, so I was wondering what exactly it is?

Thankssss,
Alex!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

残疾 2024-12-07 15:35:21

通常通过使用计时器来记录自最后一帧渲染以来已经过去了多少时间。通过 Google 可以找到许多关于该主题的文章和示例:

当然,如果你的 FPS 是允许任何东西,那么你最终会得到不切实际的模拟。因此,出现了“固定时间步长”的概念。

“调整你的时间步长!” (以及该页面上链接的以前的文章)特别是关于这个主题的好读物。

Normally by using a timer to record how much time has passed since the last frame was rendered. There are many articles and samples on the subject available via Google:

Of course if your FPS is allowed to be anything then you will end up with unrealistic simulations. For this reason there is the concept of a "fixed time step".

The "Fix Your Timestep!" (and the previous articles linked on that page) in particular is a good read on this subject.

感情洁癖 2024-12-07 15:35:21

大主题的简短回答
我想你的游戏应该放置“动画”,而不是由其帧序列号决定,而是由参考的时间延迟决定...

1)示例:1秒跳跃仅3次绘制...如果在t+0.25和t+0.75之间,则应考虑绘制#1 a t0绘制#2;如果在t+0.75和t+1之间,则应考虑绘制#3

2) 示例:如果您的移动/动画是由像positionX(intrelativeframenumber)这样的公式确定的,那么您应该考虑使用像positionX(longrelativeTimeInMillisecond)这样的时间来改变您的功能

或者在游戏循环中进行小的改变
3)在循环中放置一个“等待”代码,该代码根据连续/固定计算的帧速率性能进行校准

希望有帮助

Short answer of a large subject
I guess your game should place "animation" not determine by its frame sequences number but by the time delay from a reference...

1)example : 1 second jump with only 3 drawing ... should be considere draw#1 a t0 draw#2 if between t+0.25 and t+0.75 and draw#3 if between t+0.75 and t+1

2) example : if your move/animation is determined by a formula like positionX(int RelativeFrameNumber) your should consider change your fonction by using time like positionX(long relativeTimeInMillisecond)

or with small change in your gameloop
3) place a "wait" code in your loop that is calibrate depending a continuously/fixed computed framerate performance

Hope that help

念﹏祤嫣 2024-12-07 15:35:21

许多物理引擎在某种 update() 方法中传递增量时间。

void update(float dt)

该增量值表示与固定帧速率(例如 60fps)成比例的当前帧步长。例如,如果 dt 为 1.0,则我们的帧率为 60fps,如果 dt 为 2.0,则我们的帧率为 30fps,如果 dt 为 0.5,则我们的帧率为 120fps.. 等等

。对于任何帧速率,角色以相同的速度跳跃,将 dt 乘以对象的速度向量,以保持角色以相同的速度跳跃。

void update(float dt)
{
    myChar.Vel += myChar.Direction.Normalized() * myChar.Speed * dt;
    //myChar.Speed is in meters per second    
}

注意:二次物理需要不同的计算。

Many physics engines pass around a delta time in an update() method of some kind.

void update(float dt)

This delta value represents the current frame step proportional to a fixed frame rate (say, 60fps). For example, if dt is 1.0, then we're at 60fps, if dt is 2.0, then we're 30fps and if dt is 0.5 then we are at 120fps.. etc..

To move (in your case, jump) a character at the same speed for any frame rate, multiply dt by the object's velocity vector to keep the character jumping at the same speed.

void update(float dt)
{
    myChar.Vel += myChar.Direction.Normalized() * myChar.Speed * dt;
    //myChar.Speed is in meters per second    
}

Note: Different calculation is required for quadratic physics.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文