Pygame how to fix ‘trailing pixels’?

Normally you will do: def draw(): # fill screen with solid color. # draw, and flip/update screen. But, you can update just dirty portions of the screen. See pygame.display.update(): pygame.display.update() Update portions of the screen for software displays update(rectangle=None) -> None update(rectangle_list) -> None This function is like an optimized version of pygame.display.flip() for software … Read more

How to change an image size in Pygame?

You can either use pygame.transform.scale or smoothscale and pass the new width and height of the surface or pygame.transform.rotozoom and pass a float that will be multiplied by the current resolution. import sys import pygame as pg pg.init() screen = pg.display.set_mode((640, 480)) IMAGE = pg.Surface((100, 60)) IMAGE.fill(pg.Color(‘sienna2’)) pg.draw.circle(IMAGE, pg.Color(‘royalblue2’), (50, 30), 20) # New width … Read more

Pygame level/menu states

First of all, let’s get rid of these ugly if-blocks: for e in pygame.event.get(): if e.type == QUIT: raise SystemExit, “QUIT” if e.type == KEYDOWN and e.key == K_ESCAPE: raise SystemExit, “ESCAPE” if e.type == KEYDOWN and e.key == K_UP: up = True if e.type == KEYDOWN and e.key == K_LEFT: left = True if … Read more