Python Pygame图像不显示

Nic*_*kis 0 python pygame image

我想在pygame中显示一个游戏.但它出于某种原因,任何想法都不会起作用?这是我的代码:

import pygame, sys
from pygame.locals import *
pygame.init()
screen=pygame.display.set_mode((640,360),0,32)
pygame.display.set_caption("My Game")
p = 1
green = (0,255,0)
pacman ="imgres.jpeg"
pacman_x = 0
pacman_y = 0
while True:
    pacman_obj=pygame.image.load(pacman).convert()
    screen.blit(pacman_obj, (pacman_x,pacman_y))
    blue = (0,0,255)
    screen.fill(blue)
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
        if event.type==KEYDOWN:
            if event.key==K_LEFT:
                p=0
    pygame.display.update()
Run Code Online (Sandbox Code Playgroud)

Mar*_*eth 6

只是一个猜测,因为我实际上并没有这样做:

屏幕只是显示蓝色,你是否错过了pacman图像?可能会发生的事情是你在屏幕上插入pacman,然后做一个screen.fill(蓝色),这实际上是用蓝色覆盖你的pacman图像.尝试在代码中反转这些步骤(也就是说,将屏幕填充为蓝色,然后再打开pacman).