昨天我开始用Python做游戏,一切都很完美。我甚至解决了我一直有很长一段时间的错误。现在我终于可以从另一个文件中创建“类定义”并使我的主文件更清晰。但我现在遇到了一个错误。以前工作的东西现在已经破裂了。在课堂上我尝试更改图像时出错。
这是类代码:
<html>
<body>
<div>
<input type="text" />
</div>
</body>
</html>
运行程序时出现的错误是:
class PlayerC():
def __init__(self):
self.gender_and_image()
self.x = 128
self.y = 128
self.direction = "DOWN"
self.tile = 52
def gender_and_image(self):
self.gender = "M"
if self.gender == "M":
self.img = pygame.image.load("Textures\Dennis [Down] [1].png").convert()
self.img.set_colorkey((254, 254, 254))
def change_img(self, new_img):
self.img = pygame.image.load(new_img).convert()
player.img.set_colorkey((254, 254, 254))
错误是由于某种原因在另一个文件中。
在我让你回答之前,错误信息中的第96行是我调用函数change_img的行。
如果你能帮助我:谢谢!
编辑:
我调用change_img()的代码:
Traceback (most recent call last):
File "C:\Program Files (x86)\Wing IDE 101 5.1\src\debug\tserver\_sandbox.py", line 96, in <module>
File "C:\Program Files (x86)\Wing IDE 101 5.1\src\debug\tserver\_sandbox.py", line 43, in change_img
pygame.error: No video mode has been set
我set_mode的代码:
if going == True:
if step_factor == 1:
if playerpic == 1:
if player.gender == "M":
if player.direction == "DOWN":
player.change_img("Textures\Dennis [Down] [2].png")
playerpic = 2
elif playerpic == 2:
if player.gender == "M":
if player.direction == "DOWN":
player.change_img("Textures\Dennis [Down] [1].png")
playerpic = 1
else:
if player.gender == "M":
if player.direction == "DOWN":
player.change_img("Textures\Dennis [Down] [3].png")