属性错误:"builtin_function_or_method"对象没有属性"append"
问题描述:
此代码用于创建行走动画.我不知道是什么原因导致属性错误.
This code is to create a walking animation. I dont know what is causing an attribute error.
class player(pygame.sprite.Sprite):
def init(self):
pygame.sprite.Sprite.init(self)
self.images = []
for i in range(1, 5):
img = pygame.image.load(os.path.join('Assets','Arts','xeonsheet','xeonsheet_' + str(i) + '.png'))
self.images.append(img)
self.images = self.images[0]
self.images = self.images.get_rect
player = player()
player_list = pygame.sprite.Group()
player_list.add(player)
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/Dreamwind-Chronicles/main.py", line 121, in <module>
player = player()
File "C:/Users/User/PycharmProjects/Dreamwind-Chronicles/main.py", line 117, in init
self.images.append(img)
Attribute Error: 'builtin_function_or_method' object has no attribute 'append'
代码有什么问题?
答
目前尚不清楚您的最终意图是什么,但是通过代码进行跟踪,我可以看到您正在使用get_rect
函数覆盖self.images
./p>
It's not fully clear what your final intention is, but tracing through the code, I can see you are overwriting self.images
with the get_rect
function.
self.images.append(img)
self.images = self.images[0]
self.images = self.images.get_rect
重复此代码后,self.images
现在是get_rect
函数.
我猜想您只想删除最后两行,然后在渲染它们时访问图像的属性?
Once this code repeats, self.images
is now the get_rect
function.
I'm guessing that you'll just want to remove those last two lines and then access the properties of the image at the time you render them?