Ruby 睡眠或延迟不到一秒? [英] Ruby sleep or delay less than a second?

查看:32
本文介绍了Ruby 睡眠或延迟不到一秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 ruby​​ 制作一个脚本,该脚本必须以每秒 24 帧的速度渲染帧,但我需要在发送命令之间等待 1/24 秒.不到一秒的最佳睡眠方式是什么?

I'm making a script with ruby that must render frames at 24 frames per second, but I need to wait 1/24th of a second between sending the commands. What is the best way to sleep for less than a second?

推荐答案

sleep(1.0/24.0)

<小时>

关于你的后续问题,如果这是最好的方法:不,你可能会得到不那么平滑的帧率,因为每一帧的渲染可能不会花费相同的时间.


As to your follow up question if that's the best way: No, you could get not-so-smooth framerates because the rendering of each frame might not take the same amount of time.

您可以尝试以下解决方案之一:

You could try one of these solutions:

  • 使用每秒触发 24 次的计时器和绘图代码.
  • 创建尽可能多的帧,根据经过的时间创建运动,而不是每帧.

这篇关于Ruby 睡眠或延迟不到一秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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