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

Re: [pygame] time depending animation code



Peter Shinners schrieb:
On Sun, 2006-05-28 at 17:24 +0200, DR0ID wrote:
I'm trying to make a time dependent animation, but I'm not sure if I'm doint this right. Please take a look:

This looks pretty close. The code you have for managing the looping seems complex. It also looks like it won't be correct if multiple frames have passed when it loops around.

------------------------------------------------------------------------

def _update(self, dt, *args):
"""update frame on time difference, dt"""
self._delay += dt
numFrames = self._endFrame - self._startFrame
dframes = int(self._delay / self._interval)
self._idx = (dframes % numFrames) + self._startFrame
# self.image = MyClass.images[self._idx]



Hi

well your right, my loop around code is not correct.

This should work the same way as you proposed (or not?):



def _update(self, dt, *args):
    """update frame on time difference, dt"""

    self._delay += dt
    if self._delay>self._interval
        numFrames = self._endFrame - self._startFrame
        dframes = int(self._delay / self._interval) + self._idx
        self._idx = (dframes % numFrames) + self._startFrame
        self._delay %= self._interval
        # self.image = MyClass.images[self._idx]


It has not to make all calculations as long the self._delay is not bigger than the self._interval.



~DR0ID