我在python中比较新,并开始在pygame中编码。出于某种原因,当我在表面上渲染一些图像时,它不会对图像进行blit。但是当我最小化然后再打开它时,它工作正常。这个问题有什么问题吗?谢谢你。
非全屏错误:https://youtu.be/q_2FT8OD7O4
全屏错误:https://youtu.be/9XKnhtN5s5k
我的代码,以防万一有错误:
import pygame
displayWidth = 1920
displayHeight = 1080
pygame.init()
gameDisplay = pygame.display.set_mode((displayWidth,displayHeight),pygame.FULLSCREEN)
pygame.display.set_caption('Road Fighters')
clock = pygame.time.Clock()
car = pygame.image.load('Car.png')
grassLeft = pygame.image.load('Grass Left.png')
grassRight = pygame.image.load('Grass Right.png')
blank = pygame.image.load('Left.png')
lining = pygame.image.load('Lining.png')
miniMap = pygame.image.load('Progress.png')
miniCar = pygame.image.load('Small Car.png')
road = pygame.image.load('Road.png')
def car(x,y):
gameDisplay.blit(car, (x,y))
def draw():
gameDisplay.blit(blank,(0,0))
gameDisplay.blit(miniMap,(670,0))
gameDisplay.blit(grassLeft,(720,0))
gameDisplay.blit(lining,(1020,0))
gameDisplay.blit(road,(1030,0))
gameDisplay.blit(lining,(1610,0))
gameDisplay.blit(grassRight,(1620,0))
def gameloop():
while True:
for event in pygame.event.get():
## if event.type == 2 or event.type == 12:
## pygame.quit()
## quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT: dx = -3
elif event.key == pygame.K_RIGHT: dx = 3
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT: dx += 3
elif event.key == pygame.K_RIGHT: dx += -3
draw()
gameloop()
答案 0 :(得分:2)
您需要在游戏循环中添加pygame.display.flip()
。