我正在pygame中制作一个新游戏,blit功能对我来说不起作用,它应该很简单,但我不知道出了什么问题。
import pygame
import sys
pygame.init()
clock = pygame.time.Clock()
game = True
WIDTH = 160
HEIGHT = 144
screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)
level = pygame.image.load('RBYG/Level.png')
def redrawGameWindow():
screen.blit(level, (0, 0))
while game:
screen.blit(level,(0, 0))
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
sys.exit()
redrawGameWindow()
clock.tick(60)
您缺少pygame.display.flip()
,必须在闪电战之后执行,否则什么都不会发生。您的redrawGameWindow()
功能应翻转显示屏。此外,您在主循环中调用screen.blit(level, (0, 0))
两次,这可能是不必要的;试着只保留其中一个(只需确保之后为flip()
(。