Where should pygame.time.Clock().tick() be called in the script

119 Views Asked by At

According to this statement, pygame.time.Clock().tick() should be called at the end of the main loop. However, I couldn't see any differences on my screen display regardless where I executed that method within the loop. Could someone please give some clarification on this? Thanks

2

There are 2 best solutions below

1
Cortard On BEST ANSWER

The documentation say :

A call to the tick() method of a Clock object in the game loop can make sure the game runs at the same speed no matter how fast of a computer it runs on

So it is better to call it at the end of the loop because if you do it in the middle of your display fonction, a part of the element will be refresh before the wainting and a part after.You should call pygame.display.update() before that otherwise you refresh the screen after the "frame wait time".

3
Lexpj On

It is a common practise to place it at the end of the main loop, especially with respect to after flip or update. The documentation suggests

This method should be called once per frame. It will compute how many milliseconds have passed since the previous call.

It is thus a good practise to place it at after flip or update, which is usually done at the end of the main loop.