[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Can anyone steer me to some tutorials specifically aboutanimating multiple unrelated items simultaneouly
R. Alan Monroe wrote:
Subject says it all... Specifically UNRELATED items. Animating
multiple related items (like say, pacman and ghosts) I can comprehend,
because you typically update them all at the same frequency, once per
loop. Add in some complexity like say, having the score digits scroll
smoothly like a gas pump or an odometer, at the same time. That isn't
something that has any strict time relation to pacman and ghosts. I've
yet to find a good tutorial on this.
Perhaps have a look at the suckabots game in the gamelets section. That
code is pretty clear, and has what you want to do. Also maybe one of
the other games on the pygame.org gamelets/projects section will be
helpful. There's lots of different ways to do it.
You want to seperate the timing of the different game elements. So one
way you could do that is to have an animation class or function. Which
internally keeps track of how much time has past, and updates it's
frames accordingly.
Each frame you would pass an elapsed_time to each animation. As well as
depending on your game logic, different game events. eg, tell the
scoreboard that the score has changed, resulting in the scoreboard
animation starting its change scoreboard sequence. The scoreboard would
check to see if it has changed score recently, and if so how far along
in its score changing animation it is. If it hasn't changed score
recently it may just display the frame showing the current score.
You don't need an event system to tell the objects what's happening,
just add a method, and call it when something happens.
I did a time meter once which had ten levels of progress. Each level
was just a different image I drew in the gimp. It's a simple way to do
it without much code. Then you just say if time == 10 show the surface
with drawn with 10 levels, or if time == 1 show surface 1.
Hopefully some of that made sense :) Have fun!