我正在尝试制作游戏,代码中也有一些问题。我不知道为什么我的代码给出错误。错误是
“ AttributeError:'BarreraControlable'对象没有属性'abajo'”
class BarreraControlable(pygame.sprite.Sprite):
def __init__(self, xInicial, yInicial):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load("animaciones/barrera.png") #barrera.png? .png necesario
self.rect = self.image.get_rect()
self.rect.x = xInicial
self.rect.y = yInicial
self.subir = -8
self.bajar = 8
self.incremento = self.bajar
def lecturaEventos(self):
event = pygame.event.poll()
self.abajo = False
self.arriba = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_DOWN:
self.abajo = True
elif event.key == pygame.K_UP:
self.arriba = True
elif event.type == pygame.KEYUP:
self.abajo = False
self.arriba = False
def ejecutaPaso(self):
if self.abajo == True:
self.rect.y += self.incremento
elif self.arriba == True:
self.incremento = self.bajar
self.rect.y += self.incremento
def update(self):
self.ejecutaPaso()
答案 0 :(得分:1)
您的class TopLevelJobViewSet(ModelViewSet):
permission_classes = (IsOwner,)
serializer_class = TopLevelJobSerializer
queryset = TopLevelJob.objects.all()
filter_backends = [IsOwnerFilter, DjangoFilterBackend, RelatedOrderingFilter]
filter_class = TopLevelJobFilter
ordering_fields = '__all__'
是在方法self.abajo
中创建和分配的。在致电lectureEventos()
或lectureEventos()
之前,请确保已致电ejectutaPaso()
。
或者,如果您不希望在方法中初始化所有属性,则可以在构造函数中初始化所有属性。