1 """ Surface-based actor with multiple frames. """
4 from pgzero.clock import each_tick
5 from .orientatedsurf import OrientatedSurfActor
8 class AnimatedSurfActor(OrientatedSurfActor):
9 def __init__(self, frames, cycle_dt=0.2, **kw):
11 self._frame = random.randint(0, len(frames) - 1)
13 self._cycle_dt = cycle_dt
14 each_tick(self.update)
15 super().__init__(surf=frames[self._frame], **kw)
19 while self._dt > self._cycle_dt:
20 self._dt -= self._cycle_dt
22 self._frame %= len(self._frames)
23 self.surf = self._frames[self._frame]