每秒锁定帧数为 60fps
Locking Frames Per Second to 60fps
我在 Extra Credits on FPS 上看到了这一集,他们提到您通常应该将 fps 锁定为 30 的倍数,因为它与显示器的刷新率相匹配并减少了伪像。我的代码是 运行 在 60fps 但我仍然在运动中得到非常微妙的伪像。
https://www.youtube.com/watch?v=zL5kOyHWI_E
它在 Windows 表格中,所以也许真的没有什么可做的。
我的渲染循环看起来像这样:
private void Render() {
Update();
if (RenderDelegate != null)
RenderDelegate(_renderFunctions);
var msPause = 1000 / (double)FpsLimit - _gameTime.DeltaTime;
if (msPause > 0)
System.Threading.Thread.Sleep((int)msPause);
_attachedSystem.NextFrame(); // Will call Invalidate();
}
WinForms 控件中的实现
protected void FormOnPaint(object sender, PaintEventArgs paintEventArgs) {
_graphic = paintEventArgs.Graphics;
_render();
}
void IGameMessages.DrawImage(Image image, Rectangle rect) {
_graphic.DrawImage(image, rect);
}
void IGameMessages.NextFrame() {
Control.Invalidate();
}
我猜按动态值休眠不是首选方式,因为它可能与显示器刷新率不同步 1% 之类的? fps 输出在 58 到 63 fps 之间摆动(DeltaTime 计算也可能有问题)
WinForm 并不理想。原因是屏幕更新不依赖于您的应用程序。 WinForms 中没有屏幕中断。
我保留了一个计时器并从左向右移动了一个对象,800 像素,"sprite" 相似的对象有一个开始计数器整数。取决于过去了多少时间采取了新的立场。
if(!x.AtEnd) {
X.DeltaTime = X.Startime-currentTime;
int x = myStartTime - currentTime;
x.position = X.DeltaTime % 430; //time was in ms and 430 just a number
if (x.postion > x.end) {
x.position=x.end;
x.AtEnd=true;
}
}
这有点取决于它移动的速度和外观的数量(这也取决于计算机速度,因为较慢的计算机在其他线程上执行也需要更多时间)。使用类似上面的东西我得到了一个合理的平滑移动对象,不像游戏中那样平滑,但它运行良好并且其中没有阻塞(延迟)代码(因为我尝试使用线程延迟所以每个移动花费相同的时间,但是也没有顺利,屏幕更新太随机了)
我在 Extra Credits on FPS 上看到了这一集,他们提到您通常应该将 fps 锁定为 30 的倍数,因为它与显示器的刷新率相匹配并减少了伪像。我的代码是 运行 在 60fps 但我仍然在运动中得到非常微妙的伪像。
https://www.youtube.com/watch?v=zL5kOyHWI_E
它在 Windows 表格中,所以也许真的没有什么可做的。
我的渲染循环看起来像这样:
private void Render() {
Update();
if (RenderDelegate != null)
RenderDelegate(_renderFunctions);
var msPause = 1000 / (double)FpsLimit - _gameTime.DeltaTime;
if (msPause > 0)
System.Threading.Thread.Sleep((int)msPause);
_attachedSystem.NextFrame(); // Will call Invalidate();
}
WinForms 控件中的实现
protected void FormOnPaint(object sender, PaintEventArgs paintEventArgs) {
_graphic = paintEventArgs.Graphics;
_render();
}
void IGameMessages.DrawImage(Image image, Rectangle rect) {
_graphic.DrawImage(image, rect);
}
void IGameMessages.NextFrame() {
Control.Invalidate();
}
我猜按动态值休眠不是首选方式,因为它可能与显示器刷新率不同步 1% 之类的? fps 输出在 58 到 63 fps 之间摆动(DeltaTime 计算也可能有问题)
WinForm 并不理想。原因是屏幕更新不依赖于您的应用程序。 WinForms 中没有屏幕中断。
我保留了一个计时器并从左向右移动了一个对象,800 像素,"sprite" 相似的对象有一个开始计数器整数。取决于过去了多少时间采取了新的立场。
if(!x.AtEnd) {
X.DeltaTime = X.Startime-currentTime;
int x = myStartTime - currentTime;
x.position = X.DeltaTime % 430; //time was in ms and 430 just a number
if (x.postion > x.end) {
x.position=x.end;
x.AtEnd=true;
}
}
这有点取决于它移动的速度和外观的数量(这也取决于计算机速度,因为较慢的计算机在其他线程上执行也需要更多时间)。使用类似上面的东西我得到了一个合理的平滑移动对象,不像游戏中那样平滑,但它运行良好并且其中没有阻塞(延迟)代码(因为我尝试使用线程延迟所以每个移动花费相同的时间,但是也没有顺利,屏幕更新太随机了)