[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] frame independant movement



This is kind of a caveman method that might waste a few precious FPS, but I used it successfully (I think--I mean, nobody complained my game runs like crap. :))

Run a frame-flipping benchmark for a second or two as part of your program's startup, in which you blit the whole screen each frame and record the average FPS (or minimum FPS if you're a glass-half-full guy). Then pick some arbitrary percentage of computational overhead you want to reserve for worst-case game computations, say 10% or 15%, and shave that off the top: max_fps = bench_fps * 0.15. Then clock.tick(max_fps) to throttle your frame rate.

Hypothetically you can get near-max FPS on any system. You could then code your game speed factor in the manner described by the others in this thread.

Not all computers are created equally, though. One may excel or not in any area depending on the parts and how well they are intergrated. There may be some systems on which this kind of fudging doesn't work so you could also provide a means for the user to manually cap FPS if consistent frame rate is important.

Gumm