From: Paul Smith Date: 2009-09-09T01:44:50+09:00 Subject: Re: Time based loop limiting I think your first method is the one I've seen the most in game loops. You calculate how long you should sleep based on what time it is now and what time you want to wake up, being careful that your last frame could have taken over 1/30th of a second. You also use the elapsed time in your physics, so the physics engine is not tied to your frame rate. On Tue, Sep 8, 2009 at 5:38 PM, Michael Tomer wrote: > I'm trying to write a loop that will only run a certain number of times > per second. For instance, in Ruby-Processing, you would use > "frame_rate(30)" to make the main loop execute no more than 30 evenly > spaced frames per second. How might I go about doing something like > that? > > I could try calling sleep with a float that represents the difference > between the next time I want the loop to run and the current time. That > seems clunky, though. > > I also thought about using the Observer pattern to have a timer alert > the simulation each time it should update. That also seems wrong. > > I feel like I must be overlooking something simple. Any ideas? > -- > Posted via http://www.ruby-forum.com/. > > -- Paul Smith http://www.nomadicfun.co.uk paul@pollyandpaul.co.uk