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
On Nov 16, 12:40 am, claudio canepa <[email protected]> wrote:
> On Sun, Nov 15, 2009 at 12:46 PM, nederhoed <[email protected]> wrote:
> > Hello all, I'm very happy with Cocos2d and am on my way to create a
> > simple first game with it. Yeah!
>
> > But... I have a bird with wings that flap: 4 rotating images. A Sprite
> > object accepts only 1 image...
>
> > How can I create an animated Sprite? My first idea is to subclass
> > Sprite and swap the visible image every second or so.
> > Is this the way to go?
> > I will post my AnimatedSrite code using this option when it's done.
>
> > Thanks for you help! Robert
>
> > --
>
> Yes, preloading the images and then and then assign the Sprite .image member
> as needed would be fine.
>
> --
> claudio
--
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=.