所以我在文件中放了几个类。我的主文件名为main.py,它调用文件gameobjects.py中的类。但是,当我运行导入此文件的代码时,收到错误消息:
Traceback (most recent call last):
File "main.py", line 2, in <module>
from gameobjects import *
File "/Users/number1son100/Desktop/Pygame game/gameobjects.py", line 12
^
问题是,文件gameobjects.py只有11行!!!
以下是gameobjects.py的代码:
import pygame
from imageloader import *
class Player(pygame.sprite.Sprite):
def __init__(self, image, scale, clip):
self.image = imageLoader(image, scale, (clip))
class Background(pygame.sprite.Sprite):
def __init__(self, image, width, height):
self.originalAsset = pygame.image.load(image)
self.image = pygame.transform.scale(self.originalAsset, (width,height)
发生了什么事?
答案 0 :(得分:0)
self.image = pygame.transform.scale(self.originalAsset, (width,height) <- missing paren
应该是:
self.image = pygame.transform.scale(self.originalAsset, (width,height))
答案 1 :(得分:0)
您在最后一行末尾缺少右括号:
self.image = pygame.transform.scale(self.originalAsset, (width,height)
添加一个右括号,运行正常:
self.image = pygame.transform.scale(self.originalAsset, (width,height))