class GameObject:
def __init__(self, x=0, y=0, width=0, high=0, imName="", imAlpha=False):
self.x = x # on screen
self.y = y
self.width = width
self.high = high
self.imageName = imName
self.imageAlpha = imAlpha
self.image
def loadImage(self):
self.image = pygame.image.load(self.imageName)
self.image = pygame.transform.scale(self.image, (self.width, self.high))
if self.imageAlpha == True:
self.image = self.image.convert_alpha()
else:
self.image = self.image.convert()
pygame.init()
player = GameObject(px0, py0, width, high, "player.png", True)
player.loadImage()
任何想法,爲什麼我有以下錯誤?AttributeError:GameObject實例沒有屬性 - PyGame
AttributeError: GameObject instance has no attribute 'image'
'__init__'中單獨使用'self.image'有什麼意義?如果你想聲明,可以用'self.image = None'來代替 – PRMoureu