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

Re: [pygame] kind of animation



Peter Shinners schrieb:
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.



Hello

Thank you for your tips. I was more interessted in how and when change the image of an animation rather than moving it around. But your right, for the position one should use a float tuple because rect can only store integers.

I had planned to use rects for collision detection, but if I do, then I have to round my position coordinates to integers to use rect for that. I have to rethink that although I assume it makes not a big difference.

If I understand you right you suggest to make the objects and functions time dependent. What do you mean with "you end up with a consistent game"?

As said, I was more interested how to update the image of an animation. But this leads to a other question which I will ask in an other email.


~DR0ID