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

[pygame] Adjusting Timing With a User Event



How can I go about adjusting the speed of in-game events based on the current FPS? That is, my physics sim works in steps with a known time interval, but the _game_ might have varying FPS, and I want a thrown ball to move at a constant rate in real time regardless of how many animation frames/simulation steps happen.

Right now I've got a Pygame "clock" in my main loop to regulate game speed to a max of 30 FPS. I just now added the line:

self.time_interval = min(1.0 / clock.get_fps(),.3)

Which should change the amount of time that a simulation step represents to be either the amount of real time since the last step, or .3 s, whichever is smaller. (Bad things happen if the interval gets too big.) But it's stupid to make this adjustment every frame, right? Better to only do it once every few seconds at most. The most elegant way to do that in Pygame is probably to set a user event, but how do I do that and make it appear once every [spam] milliseconds?

Kris