简体   繁体   English

即使使用 DeltaTime,C++ Raylib 在不同 FPS 下也有不同的移动速度

[英]C++ Raylib Different Movement Speed at differents FPS even with DeltaTime

rigth now I try to make a small game with raylib and c++.现在我尝试用 raylib 和 C++ 制作一个小游戏。 Rigth now I only have a small cube and a plain window with the FPS in the corner.现在我只有一个小立方体和一个普通窗口,角落里有 FPS。 Becuase I doesnt wanted to use SetTargetFPS() I tried to implement deltaTime.因为我不想使用 SetTargetFPS() 我试图实现 deltaTime。

Rigth now I´m also calculating it and it works fine, when the FPS are stable, so for example: The cube moves at stable 200 FPS as fast as at stable 60 FPS, but when I get rid of SetTargetFPS(), so I have unstable FPS and the jump between 2000FPS and 1000FPS, The movement speed isn´t good.现在我也在计算它并且它工作正常,当 FPS 稳定时,例如:立方体以稳定的 200 FPS 的速度和稳定的 60 FPS 一样快,但是当我摆脱 SetTargetFPS() 时,所以我FPS不稳定,在2000FPS和1000FPS之间跳跃,移动速度不好。

I calculate the deltaTime so:我这样计算 deltaTime:

oldTime = newTime;
newTime = GetTime();
deltaTime = (newTime - oldTime) * 500;

That does also work and I have pretty similar numbers at the sma FPS.这也确实有效,而且我在 sma FPS 上的数字非常相似。

And that is how I move things:这就是我移动事物的方式:

newPosX = posX + addX * deltaTime;

Does somebody know why this happens?有人知道为什么会这样吗?

Thanks谢谢

I'm new to raylib but I believe the GetFrameTime() function is what you're looking for.我是 raylib 的新手,但我相信GetFrameTime()函数正是您要找的。 This is the snippet in the cheat sheet :这是备忘单中的片段:

float GetFrameTime(void);        // Returns time in seconds for last frame drawn

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM