External Exam Download Resources Web Applications Games Recycle Bin

Set Max Frame Rate

sixty_fps.py

import pygame
pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False

clock = pygame.time.Clock()
ticks = 0
while not done:
  clock.tick(60) #set framerate to max 60fps
  ticks = ticks + 1
  if ticks >= 60:
    ticks = 0
    print("60 frames / 1 second has passed.")

  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      done = True
  pygame.display.flip()
pygame.quit()