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

[pygame] update() or tick()



Hello


I asked in the past about what animation kind you use: event, time or frame based. But the more important question is how are the objects updated? One thing is shure, every object has to be updated once a frame, or even not?


First one need to know what has to be done in the main loop:

1. eventhandling
2. updating
3. drawing

I hope I did not forget something important or doing something wrong. Perhaps the order can change. So basically it goes two times trough the objects list: once for the update and once for the drawing (more or less).

In many examples and tutorials of pygame a update() method is used. This means that in the main loop in one place one has to go through the objects list and call the update() method. This is done every frame of the game.

A similar but eventbased approach is using a special event, lets call it E_tick(). But then a event dispatching mechanisme is needed and for updating the objects a special event E_tick() would be used to update the objects. E_tick() has the actual time or the time elapsed in the last frame, so the object can update accordingly (I think the elapsed time is more usefull as the absolute time but perhaps one should pass both so the object can use what it need).


What avantages or disadvantages has each of these approaches?

I think the eventbased approach is more flexible so any kind of events can be passed around. So my next question will be how to build a event dipatching mechanisme, but I will ask this in a further email.

Hope this are not too many questions at once.


~DR0ID