0
我有一些代码,我试图让一个精灵动画。但是,我需要在方法(动画)中使用方法(步行)中定义的属性(方向)。这可能吗?你可以给pygame中的同一个类中的另一个方法创建一个属性的方法吗?
class character():
init和动画在这里
def walk(self, x, y, direction):
if event.type == KEYDOWN:
if (event.key == K_LEFT):
self.x-=1
self.direction = 2
print(self.direction)
elif (event.key == K_RIGHT):
self.x+=1
self.direction = 3
elif (event.key == K_UP):
self.y-=1
self.direction = 0
elif (event.key == K_DOWN):
self.y+=1
self.direction = 1
Character.animate(direction)