tags:

views:

2579

answers:

2

So 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... how can I do that?

sleep seems to only wait in increments of 1 second or more.

update

Well ya you can do sleep 0.1 if you want, but is this the best way to delay in a ruby script?

+6  A: 
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.
Georg
+2  A: 

Pass float to sleep, like sleep 0.1

S.Mark