pygame背景图片未显示

时间:2020-08-13 00:13:23

标签: pygame

我正在研究pygame太空侵略者游戏。当我尝试使背景图像变暗时,它不起作用。我对pygame相当陌生,所以我不知道该怎么办。我尝试下载另一张图片并使用它,但是问题仍然存在。

background image

import pygame
import os
import time
import random
import math
import sys

pygame.init()
screen = pygame.display.set_mode((750,750))
pygame.display.set_caption("Space Invaders")
FPS = 60
clock = pygame.time.Clock()

#Ships
RED_SPACE_SHIP = pygame.image.load(os.path.join('assets','pixel_ship_red_small.png'))
GREEN_SPACE_SHIP = pygame.image.load(os.path.join('assets','pixel_ship_green_small.png'))
BLUE_SPACE_SHIP = pygame.image.load(os.path.join('assets','pixel_ship_blue_small.png'))
YELLOW_SPACE_SHIP = pygame.image.load(os.path.join('assets','pixel_ship_yellow.png'))

#Lasers
RED_LASER = pygame.image.load(os.path.join('assets','pixel_laser_red.png'))
BLUE_LASER = pygame.image.load(os.path.join('assets','pixel_laser_blue.png'))
YELLOW_LASER = pygame.image.load(os.path.join('assets','pixel_laser_yellow.png'))
GREEN_LASER = pygame.image.load(os.path.join('assets','pixel_laser_green.png'))

#Background
BG = pygame.transform.scale2x(pygame.image.load(os.path.join('assets','background-black.png')).convert_alpha())

def main():
    run = True

    def redraw_window():
        screen.blit(BG, (0, 0))
        pygame.display.update()

while True:
    clock.tick(FPS)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    screen.blit(BG, (0,0))
    pygame.display.update
    clock.tick(120)

pygame.quit()

1 个答案:

答案 0 :(得分:1)

调用显示更新时需要括号:

screen.blit(BG, (0,0))
pygame.display.update()  # need parenthesis
clock.tick(120)