Quick answer: Cast to int with round() at Rect construction. For float precision, use pygame.FRect.
Physics step gives float positions. pygame.Rect(player.x, player.y, w, h) warns. Silent truncation; over time, sub-pixel drift.
The Fix
# Old (warns and truncates):
# r = pygame.Rect(player.x, player.y, 32, 32)
# Option 1: explicit int
r = pygame.Rect(round(player.x), round(player.y), 32, 32)
# Option 2: float-aware (pygame-ce 2.5+)
r = pygame.FRect(player.x, player.y, 32, 32)
hits = r.collidelistall(enemy_rects) # works with FRect
# Hybrid: store FRect, convert to Rect for blit
screen.blit(player_image, pygame.Rect(player_frect))
FRect is the cleanest option for sim-driven coordinates. Keep Rect for blit/UI where pixel-rounding matters anyway.
Verifying
Run with -W error::DeprecationWarning: no warning raised. Sub-pixel drift visible with FRect — expected, not a bug.
“Round on construction. Or use FRect. Warning gone.”
Related Issues
For Clock.tick vsync, see Clock vsync. For mixer end event, see music end.
Round or FRect. Warning gone.