简体   繁体   中英

Pygame won't draw or fill screen

I posted this question yesterday, but I accidentally posted the wrong code. The program still doesn't work though. I am trying to make a game using pygame and my pictures come from an app called Pixel Art Studio. When I run the code though, I don't get any error messages, just a blank, white screen. I'm following a python programming book called Hello World but this is an original program. Please tell me what I've done wrong, here's my code.

import pygame, sys 
guyimages = ['swordsmanguy.pxm','swordsmanstabup.pxm','swordsmanstabstraight.pxm','swordsmanstabdown.pxm']
legsimages = ['swordsman.legs1.pxm','swordsman.legs2.pxm','swordsman.legs3.pxm','swordsman.legs2.3.pxm','swordsman.legs2.2.pxm']
class avatar(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprit.Sprite.__init__(self)
        self.image = pygame.image.load(guyimages["swordsmanguy.pxm"])
        self.rect = self.image.get_rect()
        self.rect.center = [250, 250]
        self.angle = 0

def animate():
    screen.fill([255,255,255])
    screen.blit(avatar.image, avatar.rect)
    pygame.display.flip

pygame.init()
screen = pygame.display.set_mode([960, 640])

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    animate()
pygame.quit()

You are missing parentheses after animate in the code you posted.

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    animate #HERE MISSING PARENTHESES

When you set self.image you reference the guyimages list like it's a dictionary. Additionally, there seem to be some parentheses missing from your code. Do you get an error in the terminal / command prompt window from which you run this script?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM