Python(2.7)Pygame空白屏幕

时间:2018-12-03 18:22:13

标签: python pygame

我正在尝试运行一个小的pygame代码。当我运行代码时,它很简单,却显示白屏。我已经阅读了几个论坛并发表了文章,但似乎无法弄清楚。

我的代码是

# 1 - Import library
import pygame
from pygame.locals import *

# 2 - Initialize the game
pygame.init()
width, height = 640, 480
screen=pygame.display.set_mode((width, height))

# 3 - Load images
player = pygame.image.load("resources/images/dude.png")


# 4 - keep looping through
while 1:
    # 5 - clear the screen before drawing it again
    screen.fill(0)
    # 6 - draw the screen elements

    screen.blit(player, (100,100))
    # 7 - update the screen
    pygame.display.flip()
    # 8 - loop through the events
    for event in pygame.event.get():
        # check if the event is the X button
        if event.type==pygame.QUIT:
            # if it is quit the game
            pygame.quit()
            exit(0)

将寻求任何帮助。谢谢。

0 个答案:

没有答案
相关问题