Pygame Movement Stuttering

6 days ago 12
ARTICLE AD BOX

When I try to move Surface in Pygame, it seems to stutter in a weird way. Even when I use dt, the movement speed is not constant. Even thought FPS oscilate around 59-61, the Surface sometimes moves just a few, pixels and sometimes makes a big jump ahead. Theres no visible lag, or pause between the frames. I've seen this problem occur in many Pygame projects.

I haven't found any working fix to this problem, except using higher framerate rates.

import pygame # setup pygame.init() screen = pygame.display.set_mode((800, 600)) clock = pygame.time.Clock() # start position of rect x = 0 dt = 0 running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False # move react x += 200 * dt # refresh screen.fill("black") # draw rect on Surface pygame.draw.rect(screen, "white", (x, 200, 50, 50)) # flip pygame.display.flip() dt = clock.tick(60) / 1000
Read Entire Article