【发布时间】:2018-01-14 18:45:19
【问题描述】:
我正在修改我在网上找到的一个程序,我正在尝试加载一个 .png 而不是以前的块精灵,但我认为我在尝试加载它时编码不正确。代码如下:
class Player(pygame.sprite.Sprite):
"""
This class represents the bar at the bottom that the player controls.
"""
# -- Methods
def __init__(self):
""" Constructor function """
# Call the parent's constructor
super().__init__()
# Create an image of the block, and fill it with a color.
# This could also be an image loaded from the disk.
image.self.pygame ("Sprite-01.png")
# Set a referance to the image rect.
self.rect = self.image.get_rect()
# Set speed vector of player
self.change_x = 0
self.change_y = 0
# List of sprites we can bump against
self.level = None
这是错误:
Traceback (most recent call last):
File "C:/Users/1234/AppData/Local/Programs/Python/Python36-32/class 10 program St.Patrick.py", line 452, in <module>
main()
File "C:/Users/1234/AppData/Local/Programs/Python/Python36-32/class 10 program St.Patrick.py", line 360, in main
player = Player()
File "C:/Users/1234/AppData/Local/Programs/Python/Python36-32/class 10 program St.Patrick.py", line 51, in __init__
image.self.pygame ("Sprite-01.png")
NameError: name 'image' is not defined
【问题讨论】: