0

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

Nemo
  • 1,124
  • 2
  • 16
  • 39

2 Answers2

1

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.

Lexpj
  • 921
  • 2
  • 6
  • 15
  • Thanks for your answer. I did read that part of the docs but couldn't understand what `per frame` meant. Would you mind elaborating on that `frame` thing with an example? Also, what is the benefit/purpose of computing how many milliseconds have passed? – Nemo Jun 02 '23 at 10:37
  • 1
    A frame is the considered the last blit to the display. This is usually when you have blitted everything to the display surface, and you are calling `pygame.display.update` or `pygame.display.flip` in order to display this surface. Furthermore the benefit of computing the amount of miliseconds that have passed, you can keep track of the heavyness of your program. For instance, if you target at 60 FPS, and your program does not reach this, there might be some heavy calculation or blitting process that cannot happen 60 times a second. – Lexpj Jun 02 '23 at 10:42
  • Wonderful! Thanks for the explanation! – Nemo Jun 02 '23 at 10:48
1

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".

Cortard
  • 72
  • 5