Ruby sleep or delay less than a second?
Solution 1:
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.
Solution 2:
Pass a float
to sleep
, like:
sleep 0.1