如何将帧速率限制在 60fps?
好吧,所以我试图将帧速率限制在每秒 60 帧,但我使用的方法将其减慢到 40 帧左右。
#define TICK_INTERVAL 30
Uint32 TimeLeft(void){
static Uint32 next_time = 0;
Uint32 now;
now = SDL_GetTicks();
if ( next_time <= now ) {
next_time = now+TICK_INTERVAL;
return(0);
}
return(next_time-now);
}
然后我这样调用它: SDL_Delay(TimeLeft());< /code>
如何限制我的帧速率而不超过它,或者让它太快地限制它?
Alright, so I'm trying to cap my framerate at 60 frames per second, but the method I'm using is slowing it down to like 40.
#define TICK_INTERVAL 30
Uint32 TimeLeft(void){
static Uint32 next_time = 0;
Uint32 now;
now = SDL_GetTicks();
if ( next_time <= now ) {
next_time = now+TICK_INTERVAL;
return(0);
}
return(next_time-now);
}
Then I call it like this: SDL_Delay(TimeLeft());
How can I cap my framerate without going over it, or having it cap it too soon?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要记录绘制当前帧之前的时间,然后从之后延迟适当的时间。
例如,一些伪代码会
标记Time是调用drawFrame()之前记录的时间。 DelayFrom() 是一个从给定时间而不是“现在”开始延迟的函数。 1/60 是从第一个参数开始延迟的时间量(以秒为单位)。
You need to record the time before drawing the current frame, and then delay the appropriate amount from then.
For example, some pseudo code to do it would be
markedTime is the time recorded before drawFrame() was called. delayFrom() is a function that delays from a given time instead of "now". 1/60 is the amount of time to delay from the first argument, in seconds.