Search code examples
pythonpygamepygame-clock

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


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


Solution

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