【发布时间】:2020-03-13 00:58:45
【问题描述】:
我尝试正常运行代码,但是遇到了一个看起来像这样的错误
Traceback (most recent call last):
File "H:\Coursework assets\gametest1.py", line 85, in <module>
wizard.move(wizard.x)
AttributeError: 'tuple' object has no attribute 'move'
下面是主角的原始玩家类。错误可能源自何处
class player:
def __init__(self,x,y):
self.x = x
self.y = y
self.standing = True
self.left = False
self.right = True
self.vel = 15
def move(self,x,y):
if not(self.standing):
if k[pygame.K_LEFT] and self.x > 0 - 150:
self.left = True
self.right = False
self.x -= self.vel
elif k[pygame.K_RIGHT] and self.x < 500 - 150 :
self.right = True
self.left = False
self.x += self.vel
else:
self.standing = True
run = True
主游戏循环
wizard = (25,420)
while run:#main game loop
pygame.time.delay(15)
wizard.move(wizard.x,wizard.y)
win.blit(bg,(0,0))
wizard.jump(wizard.y)
wizard.draw(win))
pygame.display.update()
pygame.quit()
【问题讨论】:
-
我对您的变量“向导”应该是什么深感困惑!您已为其分配了一个元组,但您似乎试图将其视为您的播放器类的实例!你的意思是设置一个叫精灵的播放器?在这种情况下,您需要将游戏循环的第一行替换为 'wizard = player(45,420)'
标签: python python-3.x oop pygame attributeerror