[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Animating sprites



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"