[英]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.
我正在尝试使用pygame制作游戏,而我的图片来自名为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.
我正在看一本叫做Hello World的python编程书,但这是一个原始程序。 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. 设置self.image时,您引用的
guyimages
列表就像字典一样。 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?
在运行此脚本的终端/命令提示符窗口中是否出现错误?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.