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

[pygame] Clock versus time tick checks



Hi,
 I'm going to be introducing animation and want to ensure a steady frame rate. I see two approaches to this right now from reviewing examples. One is to use a Clock with a frame rate argument. This appears to simply do a delay any time there are spare milliseconds till the name frame update. The second approach which I see in piman's sprite example (http://kai.vm.bytemark.co.uk/~piman/writing/sprite-tutorial.shtml) seems instead to ask each sprite to look at a time stamp and based on that, update or not (i.e. every 10 milliseconds since last time updated show a new frame or location).  The first has the appeal of using a pygame specific mechanism for frame rates (Clock) but the second seems like it does waste cycles. That is it seems like if I had things to do with spare cycle like do some AI I could use the time as opposed to having it absorbed by a Clock controlled frame rate.
  Leaving aside my perhaps erronious latter intuition, my question is this: what would you recommend as preferred way to control  frame rate for animations...on whatever basis you would argue for :-)
  Thanks for your time,
    Lin
 
p.s. For more context, I'm using sjbrown's Writing Games Tutorial where he generates tick events as fast as a loop can manage. These tickevents then spawn subevents like display updates.  I'm thinking I either have these tick events simply communicate the absolute time in style of piman code  or at each return to generate a new tickevent do a clock frame rate delay. Please let me know if any further advise or comments given I'm using that kind of Mediator architecture.