[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Adjusting Timing With a User Event
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Adjusting Timing With a User Event
- From: Kris Schnee <kschnee@xxxxxxxxxx>
- Date: Thu, 19 Apr 2007 11:46:53 -0400
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Thu, 19 Apr 2007 11:47:07 -0400
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Thunderbird 1.5.0.10 (Windows/20070221)
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