[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Adjusting Timing With a User Event
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Adjusting Timing With a User Event
- From: Luke Paireepinart <rabidpoobear@xxxxxxxxx>
- Date: Thu, 19 Apr 2007 10:56:38 -0500
- 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:57:02 -0400
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=GodgK1OILtNb+6FpyZICzhappV0EIpZdDwRszqXrlQGWUxgKhoIViXKx33UqCh85ZvqNeLOtANyGYTzTot0kUQ6Il2y2Fw/I22EmjwTI9JE2fo5uh+UA5mf0eKCS9HwJ+Rt/xhSgyrwDyrOKXSjFDto6sI97gJjbP80Qmx+z0XI=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=Sq0eJaSOid+N0oxZbkEYnlhim0ix6rrBURbKzjp5nv8FyMZOpofXqCh1Bw82qSEhbZrRikU7On7MwWfAB5PLWjvEvEijTA9Tg1OojlLTE+zgaTnkOfMX73hLtjUZis4GBUfY7EED3yKboNN6fpNHXXPJuzSRs4amd6EKDtVMrUA=
- In-reply-to: <46278EED.5060407@xepher.net>
- References: <46278EED.5060407@xepher.net>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Thunderbird 1.5.0.10 (Windows/20070221)
Kris Schnee wrote:
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?
The only problem with a user event would be in that it would take up one
event slot (since you're writing a library you'd want to try to restrict
things like that, I'd assume.)
actually, another problem is that your physics sim would have to have
access to the event queue, or the client would have to call fix_yourself
(or whatever you name the function) whenever the event arose.
IMHO, the client shouldn't be required to keep your sim updated in that way.
pygame.time.set_timer(EventCode,HowOftenToEnqueueIt)
that's all you have to do, I believe.
HowOften is in milliseconds, so 300 would be every .3 milliseconds.
HTH,
-Luke
Kris