1
我是pygame的新手,尝试创建一个简单的程序,允许我使用键盘在屏幕上移动图像。在使用外观方法尝试在屏幕上显示图像时,出现标题错误。我有一个我没有使用类编写的工作版本,但想了解类,以便将来可以实现它们。TypeError:参数1必须是pygame.Surface,而不是方法
这里是我的代码:
import pygame, sys
from pygame.locals import *
pygame.init()
FPS = 30
fpsClock = pygame.time.Clock()
DISPLAYSURF = pygame.display.set_mode((600, 500), 0, 32)
pygame.display.set_caption('Animation')
class Hero():
def __init__(self):
posx = 10
posy = 10
def appearance():
return pygame.image.load('C:\\Users\\admin\\Desktop\\right.png')
def move_right(x):
posx += 10
def move_left(x):
posx -= 10
def move_up(y):
posy -= 10
def move_down(y):
posy += 10
new_hero = Hero() #create a Hero
while True:
item = new_hero.appearance
DISPLAYSURF.blit(item, (posx, posy)) #error
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
fpsClock.tick(FPS)