On Wed, Feb 3, 2010 at 7:06 PM, DR0ID <[email protected]> wrote: > On 03.02.2010 11:25, inigo delgado wrote: >> >> "Another thing you can do is just use Clock to limit the FPS to 60 or >> something, but then your game will run slower if you're not getting 60 fps." >> >> Well, true, but you MUST determine the framerate that you want for your >> game, otherway you will get a 60 FPS in your PC, 70 in another and 120 in >> another one that is much more faster/newer than yours and in witch your game >> will turn unusable at this framerate.... >> >> I do this: >> >> while(true): #principal loop >> # get current time >> t = time.time() >> .... >> doAll() >> .... >> #At the end i get the time needed to do the calculatons & flip >> T = t - time.time() >> delta = T - 1/desiredFrameRate >> if (delta > 0): # if the cycle has been done too fast >> time.wait(delta) >> ####This way you have your desired framerate or the maximum possible. >> Additionally you can do this: >> else: >> GLOBAL_T = GLOBAL_STANDAR_T - delta # delta is <= 0, - and - is + >> >> Being GLOBAL_T the t that you use for your position calculations and >> global_standar_t the value of global_t if delta is 0. > > Hi > > You will get different framerates only if you don't limit the fps. Using > http://www.pygame.org/docs/ref/time.html#Clock.tick you will have always the > specified framerate except if the cpu can not keep up (then it will run > slower), but on faster machines tick will wait, similar to what you do (tick > might be more accurate). > > ~DR0ID >
Just another note... use Clock.tick_busy_loop if you don't mind burning a bit of cpu to get far more accurate sleeping. The OS sleep is often a bit random - and not really meant for accurate sleeping. cu,
