问题描述
imgs = [pygame.image.load("myimg1.png"),pygame.image.load("myimg2.png"),pygame.image.load("myimg3.png")]
class ParentClass:
def __init__(self,imgs,coordinates):
self.imgs = imgs
self.index = 0
self.activeImg = imgs[self.index]
self.x,self.y = coordinates
class ChildClass(ParentClass):
def __init__(self,coordinates):
super().__init__(imgs,coordinates)
#more stuff
child = ChildClass(imgs,(100,100))
错误:
TypeError: 'pygame.Surface' object is not subscriptable
imgs = [pygame.image.load("myimg1.png"),startImg,coordinates):
self.imgs = imgs
self.index = 0
self.activeImg = startImg
self.x,imgs[0],100))
我不明白为什么这个错误会出现在我的主代码中。据我所知,这个图像列表应该没有任何错误地编入索引。 Python 似乎在想我正在索引 pygame.Surface 对象(显然不是我在做什么)。但另一方面,当我将它作为参数传递时,它运行时没有任何错误(我觉得这很令人困惑)。
帮助将不胜感激。谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)