【发布时间】:2020-08-15 16:36:47
【问题描述】:
我正在开发一款名为 Scuba Adventure 的游戏,在尝试查找属性错误的来源时,我遇到了另一个错误,上面写着“来自外部范围的物体阴影”。我发现错误的根源是缩进。在定义一个名为 Bubble 的类来控制气泡对象和精灵组时,我不小心将 def __init__() 中的方法缩进了。我的课是这样的:
import pygame
from pygame.sprite import Sprite
class Bubble(Sprite):
"""A class that manages bubbles released from the diver."""
def __init__(self, sa_game):
"""create a bubble object at the diver's current position."""
super().__init__()
"""Some attributes"""
"
"
# import the bubble image
"""Code to import the bubble image"""
# Store the bubble's position as a decimal value
""" """
def update(self):
"""Move the bubble up the screen."""
# Method to update the decimal position of the bubble
def blit_bubble(self):
"""Method to draw the bubble at the diver's current location"""
函数体本身并不重要。但我想知道的是“从外部范围阴影”是什么意思,为什么缩进错误会抛出它。我还是个初学者,所以这个概念对我来说可能是新概念
【问题讨论】: