[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Animating sprites
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Animating sprites
- From: andrew baker <failrate@xxxxxxxxx>
- Date: Sat, 7 May 2005 15:25:01 -0700
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Sat, 07 May 2005 18:25:31 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=G8Et8m7+7xE+9QeOE8+9nthi6JAWXF26NhVbGG/d1zgAw81wWl/qfGov82QJmUH5utH8CrS4Z+KBpYvU6yYqUP+nKP2C6yk5TfF5e0MxsUWsni3vKbkjVUNYInZ6DWF7FK5fNzivjCJi4A0QH/MrjGzpRb/s6HlHuaxOEhJC0t8=
- In-reply-to: <e41aa83c05050715027c505107@mail.gmail.com>
- References: <e41aa83c05050715027c505107@mail.gmail.com>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Well, that sprite should belong to a group, so you have your animation
code in its update method. I prefer a list of images, ImageList, from
which you can create loops with tuples (for example, go_up =
(1,2,3,4), go_down = (5,6,7,8), etc.). Then, depending on its state,
current_loop = whatever loop you need.
Then, in your update method, you just check how long it's been since
your last frame, and if it's time to update frames, then:
if self.frame_count >= len(self.current_loop):
self.frame_count = 0
else:
self.frame_count++
when displayed, the Sprite should display the image:
self.ImageList[self.current_loop[self.frame_count]]
That should do it, nicely :D
On 5/7/05, Chris Smith <maximinus@xxxxxxxxx> wrote:
> What's the best way to animate a sprite in the background? I am
> writing a turn based strategy game (http://www.spqr-game.co.uk/),
> which I've written a gui for. I need to animate a sprite in the
> background (actually mainly flashing on and off, or, if python is fast
> enough, fade it in and out). No mention of this sort of stuff in the
> sprite module and I'd rather avoid using threads if possible :-) Any
> ideas?
>
> - Chris
>
> --
> Science is open source religion
>
--
Andrew Ulysses Baker
"failrate"