-1

我在我的代码中做错了什么它说这个错误消息 unindent 与代码中的任何外部缩进级别不匹配你可以重写它来告诉我在哪里改变

import pygame

# Intialize the pygame
pygame.init()

# create the screen
screen = pygame.display.set_mode ((800, 600))

# Caption and Icon
pygame.display.set_caption("Space Invader")
icon = pygame.image.load("spaceship (1).png")
pygame.display.set_icon(icon)

# Player
playerImg = pygame.image.load('space-invaders(1).png')
playerX = 370
playerY = 480


def player():
    screen.blit(playerImg, (playerX, playerY))


# Game loop
running = True
while running:

    # RGB = Red, Green, Blue
    screen.fill((0, 0, 0))

   for event in pygame.event.get():
       if event.type == pygame.QUIT:
           running = False



   player()
   pygame.display.update() 
4

1 回答 1

0

请看以下部分:

while running:

    # RGB = Red, Green, Blue
    screen.fill((0, 0, 0))

   for event in pygame.event.get():

您会看到 for 比上面的行缩进了一个字符。

这是你的错误。

所以多缩进for一个字符应该可以解决问题:

while running:

    # RGB = Red, Green, Blue
    screen.fill((0, 0, 0))

    for event in pygame.event.get():

只是打字/格式错误。

请检查它是否有效,告诉我,我将删除我的答案,您可以关闭问题。

如果我理解得很好。应从堆栈溢出中删除错字/格式问题。

于 2020-06-08T01:00:01.310 回答