簡體   English   中英

Pygame將不會繪制或填充屏幕

[英]Pygame won't draw or fill screen

我昨天發布了這個問題,但是我不小心發布了錯誤的代碼。 該程序仍然無法運行。 我正在嘗試使用pygame制作游戲,而我的圖片來自名為Pixel Art Studio的應用程序。 但是,當我運行代碼時,我沒有收到任何錯誤消息,只是一個空白的白色屏幕。 我正在看一本叫做Hello World的python編程書,但這是一個原始程序。 請告訴我我做錯了什么,這是我的代碼。

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()

在發布的代碼中設置動畫后,您會缺少括號。

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

設置self.image時,您引用的guyimages列表就像字典一樣。 此外,您的代碼似乎缺少一些括號。 在運行此腳本的終端/命令提示符窗口中是否出現錯誤?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM