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

Re: [pygame] kind of animation



On Mon, 2006-05-15 at 22:34 +0200, DR0ID wrote:
> I want to implement some animation and came up with 3 different ways to 
> do that:
> 
> 1. frame based animation
> 2. time based animation
> 3. event based animation

I'd have to say go with time based animation. It's not really harder
than frame based and you end up with a consistent game. I will offer the
following tips:

Keep all your times and positions as floating point values. This means
you won't be able to store positions with pygame.Rect

Pay attention when you have something that randomly happens each frame.
You'll need to scale the odds of things happening by how long the frame
took. A better approach is to randomly pick an amount of time for the
next "event" to happen and wait for that. Then you could fire multiple
events in a single frame if it took too long.

There really isn't much in there to worry about. You'll need floating
point positions anyways once you want something that moves slower than
one pixel per frame.