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

Re: [pygame] time depending animation code



Hello

I'm trying to make a time dependent animation, but I'm not sure if I'm doint this right. Please take a look:

#------------------------------------------------------------------------------


def _update(self, dt, *args): # dt is the elapsed time in the last frame (main loop)
self._delay += dt # accumulate passed time since last image change
if self._delay > self._interval: # if passed time is bigger as the animation interval
dframes = int(self._delay/self._interval) # calculate number of frames to move on (if dt is big it will skip images)
self._idx += dframes # move animation index
if self._idx > self._endFrame: # check if end of animation is reached
self._idx = self._startFrame # restart loop endless looping
self._delay %= self._interval # start accumulating time with already past time of next intervall<--IS THIS CORRECT?
# do other stuff here set: self.image = self.images[self._idx] or something like this



#------------------------------------------------------------------------------



Perhaps it can be done in a faster or simpler way, if so, tell me please.

Thank you for your help.


~DR0ID