import os, sys
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.mouse.set_visible(False)
def loadimage(name, colorkey=None):
try:
pygame.image.load(os.path.join(name))
except pygame.error, message:
print "Failed to load image ",name
class Userplane(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image, self.rect = loadimage("userplane.bmp")
def update(self):
pos = pygame.mouse.get_pos()
self.rect.midtop = pos
def main():
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.mouse.set_visible(False)
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((255,255,255))
screen.blit(background, (0,0))
pygame.display.flip()
user = Userplane()
allsprites = pygame.sprite.RenderPlain((user))
clock = pygame.time.Clock()
while 1:
clock.tick(60)
for event in pygame.event.get():
if event.type == QUIT:
return
elif event.type == KEYDOWN and event.key == K_ESCAPE:
return
allsprites.update()
screen.blit(background(0,0))
pygame.display.flip()
if __name__ == '__main__': main()
嗨,我很新,我刚刚完成了 pygame 教程中的 codeacademy 课程和 chimppunch 游戏。我使用的是该游戏的几乎完全相同的副本,但我试图在屏幕底部显示一个飞机而不是拳头。我的 Userplane 类不断抛出以下错误,我不知道为什么,'typeerror:'nonetype' object is not iterable