开发者

Ruby sleep or delay less than a second?

开发者 https://www.devze.com 2022-12-24 21:04 出处:网络
I\'m making a script with ruby that must render frames开发者_Python百科 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 l

I'm making a script with ruby that must render frames开发者_Python百科 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:

  • Use a timer which fires 24 times a second with the drawing code.
  • Create as many frames as possible, create the motion based on the time passed, not per frame.


Pass a float to sleep, like:

sleep 0.1
0

精彩评论

暂无评论...
验证码 换一张
取 消