Skip to content

Instantly share code, notes, and snippets.

@jtiai
Created March 4, 2020 18:03
Show Gist options
  • Save jtiai/f877ebd73feec6f55a6929866dcf5608 to your computer and use it in GitHub Desktop.
Save jtiai/f877ebd73feec6f55a6929866dcf5608 to your computer and use it in GitHub Desktop.
VSYNC
# I already added code to enable it. It should just work
# But it doesn't work on my machine either. I just followed the SDL2 docs...
# https://wiki.libsdl.org/SDL_CreateRenderer#flags
# You need to pass in SCALED to display.set_mode and have PYGAME_VSYNC=1 in your env vars
# vsync with opengl works differently
# vsync without SCALED is not planned by SDL2.
import os
os.environ["PYGAME_VSYNC"] = "1"
import pygame
pygame.init()
screen = pygame.display.set_mode((320, 240), pygame.SCALED)
clock = pygame.time.Clock()
print(pygame.display.get_renderer_info())
s = pygame.Surface((50, 50))
s.fill((255,255,255))
r = s.get_rect(center=(160, 120))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
pressed = pygame.key.get_pressed()
if pressed[pygame.K_LEFT]:
r.x -= 1
if pressed[pygame.K_RIGHT]:
r.x += 1
clock.tick()
pygame.display.set_caption(f"{clock.get_fps():02.02f}")
screen.fill((0, 0, 0))
screen.blit(s, r)
pygame.display.flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment