Created
March 4, 2020 18:03
-
-
Save jtiai/f877ebd73feec6f55a6929866dcf5608 to your computer and use it in GitHub Desktop.
VSYNC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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