Pygame – Issues creating projectiles, “add() argument after * must be an iterable, not int”

The issue is not the pygame.sprite.Group.add operation, but the obejct you want to add is not a pygame.sprite.Sprite object, because the object is not constructed at all. You missed to the super call in the constructor of Projectile. Furthermore the name of the constructor has to be __init__ rather _init_: class Projectile(pygame.sprite.Sprite): #Initialize values def … Read more

Why does pygame.display.update() not work if an input is directly followed after it?

Call pygame.event.pump() after pygame.display.update() and before input(”): def main(): pygame.draw.rect(screen,[235,235,235],(200,200,200,200)) pygame.display.update() pygame.event.pump() input(”) At some OS, pygame.display.update() respectively pygame.display.flip() doesn’t update the display directly. It just invalidates the display and notifies the system to update the display. Actually the display is updated when the events are handled. The events are either handled by either pygame.event.pump() … Read more

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.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