背景图像不会出现在屏幕上

时间:2015-07-07 01:50:27

标签: python pygame

我正在尝试运行我在网上找到的教程中的代码。

但是当我运行此代码时,我的背景图像不会出现,即使它正确加载。

为什么?

bif = "castle.jpg"
import pygame, sys, pygame.mixer

from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((1280,960),0, 32)

background = pygame.image.load(bif).convert()
pygame.display.set_caption("castlevania ultimate")

hit_sound = pygame.mixer.Sound("02.wav")
hit = False

if hit is True:
    hit_sound.play()

sound = pygame.mixer.Sound("castlevania_1.wav")
sound.play()

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

    screen.blit(background, (0,0))

pygame.display.update()

1 个答案:

答案 0 :(得分:0)

您永远不会在pygame.display.update()循环中致电while

Python是缩进敏感的,所以循环应如下所示:

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

    screen.blit(background, (0,0))

    pygame.display.update()

请注意,pygame.display.update()现在 while循环中。