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 Tue, Nov 17, 2009 at 1:22 AM, <[email protected]> wrote:

>  Today's Topic Summary
>
>    - How can I create an animated Sprite from multiple 
> images?<http://mail.google.com/mail/?ui=2&view=js&name=js&ver=Jd8O_KZeLH0.en.&am=!Sg304q2GSli5Bbvy0fc6WqpH7hNOvXL9bOpPuUjRci9h#1250105171c970b6_group_thread_0>[2
>  updates]
>
>  Topic: How can I create an animated Sprite from multiple 
> images?<http://groups.google.com/group/cocos-discuss/t/356aa27df381941f>
>
>    nederhoed <[email protected]> Nov 15 11:31PM -0800
>
>    Thanks Claudio, that sounds better than what I did: collecting Sprits
>    internally.
>
>    tonight I will update the code with your suggestion: loading internal
>    Image instances rather than Sprite instances.
>
>    My code from yesterday:
>
>    class AnimatedSprite(Sprite):
>    def __init__(self, images, *args, **kwargs):
>    super(AnimatedSprite, self).__init__(images[0], *args,
>    **kwargs)
>    self._sprites = [Sprite(i) for i in images]
>    # Loop
>    self._active_sprite = 0
>    self.schedule_interval(self.update, 0.2)
>
>    def draw(self):
>    """Draw the currently active Sprite """
>    self._sprites[self._active_sprite].position = self.position
>    self._sprites[self._active_sprite].scale = self.scale
>    self._sprites[self._active_sprite].draw()
>
>    def update(self, dt):
>    self._active_sprite = (self._active_sprite + 1) % len
>    (self._sprites)
>
>
>    It's open source:
>
>    
> http://bazaar.launchpad.net/~nederhoed/monkeyjungle/trunk/annotate/head%3A/animate.py
>
>
>    Thanks, keep up the good work! Robert-Reinder
>
>
>
>
>
>    nederhoed <[email protected]> Nov 16 02:17PM -0800
>
>    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]<cocos-discuss%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/cocos-discuss?hl=.
>

--

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