look at http://www.pyglet.org/doc/api/pyglet.image.Animation-class.html
and pyglet sprite http://www.pyglet.org/doc/api/pyglet.sprite.Sprite-class.html
(which is what cocos sprite wraps) you can actually already pass a
list of images to the sprites constructor as an Animation object
instead of a single image. It is useful to subclass sprite though to
store a couple different Animations so you can switch states by
reassigning the self.image to the new animation but the Animation
class pretty much already does what you did in your class.

Devon

On Nov 16, 5:17 pm, nederhoed <[email protected]> wrote:
> Okay, updated the code, 
> FYI:http://bazaar.launchpad.net/~nederhoed/monkeyjungle/trunk/annotate/he...
>
> 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