Okay, updated the code, FYI:
http://bazaar.launchpad.net/~nederhoed/monkeyjungle/trunk/annotate/head%3A/animate.py

class AnimatedSprite(Sprite):
    """Sprite behaviour, while continuously looping through a series
of images.

    TODO: dynamic animation logic, maybe something with state
transitions.
    """
    def __init__(self, image_filenames, *args, **kwargs):
        """Constructor """
        super(AnimatedSprite, self).__init__(image_filenames[0],
                                             *args, **kwargs)
        # Load images from file
        self._images = []
        for filename in image_filenames:
            pic = pyglet.image.load(filename)
            pic.anchor_x = pic.width // 2
            pic.anchor_y = pic.height // 2
            self._images.append(pic)
        # Loop helpers
        self._active_sprite = 0
        self.schedule_interval(self.update, 0.2)  # 5 fps

    def update(self, dt):
        """Schedule this function to enable the change of images """
        self._active_sprite = (self._active_sprite  + 1) % len
(self._images)
        self.image = self._images[self._active_sprite]

Easy! :-) Cheers, Robert-Reinder

--

You received this message because you are subscribed to the Google Groups 
"cocos2d discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cocos-discuss?hl=.


Reply via email to