为什么我得到一个黑屏在pygame即使表面似乎已经放置正确

  • 本文关键字:表面 pygame 一个 python pygame
  • 更新时间 :
  • 英文 :


我是Python的新手,我正在跟随一个名为Pygame终极介绍的youtube视频。我已经有了一切工作,我只是打开文件,开始添加更多的代码,我的屏幕不再填充。它应该展示的是天空、地面、一个小太空人和一只从左向右移动的蜗牛。看起来表面是被放置的,因为我仍然可以在屏幕上与它们交互并让打印语句运行,但它只是黑色的。

这里的代码,我不确定如何甚至开始故障排除,因为我没有得到一个追溯或任何东西。从技术上讲,这一切都在工作。
import pygame
from sys import exit
pygame.init()
screen = pygame.display.set_mode((800, 400))
pygame.display.set_caption("Runner")
clock = pygame.time.Clock()
test_font = pygame.font.Font("font/pixeltype.ttf", 75)
sky_surface = pygame.image.load('graphics/sky.png').convert_alpha()
ground_surface = pygame.image.load('graphics/ground.png').convert_alpha()
score_surface = test_font.render("Runnin' Round!", False, (64, 64, 64))
score_rect = score_surface.get_rect(midtop=(400, 50))

snail_surface = pygame.image.load("graphics/snail/snail1.png").convert_alpha()
snail_rect = snail_surface.get_rect(bottomright=(600, 300))
player_surface = pygame.image.load("graphics/player/player_walk_1.png").convert_alpha()
player_rect = player_surface.get_rect(topleft=(80, 200))
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
# if event.type == pygame.MOUSEMOTION:
#    if player_rect.collidepoint(event.pos): print("collision") #works with black screen??
screen.blit(sky_surface, (0, 0))  # place sky
screen.blit(ground_surface, (0, 300))  # place ground
pygame.draw.rect(screen, '#c0e8ec', score_rect)
pygame.draw.rect(screen, '#c0e8ec', score_rect, 10)
screen.blit(score_surface, score_rect)
print('placed background') #test to see if above is broke
snail_rect.x -= 5
if snail_rect.right <= 0:
snail_rect.left = 800
screen.blit(snail_surface, snail_rect)  # place snail
screen.blit(player_surface, player_rect)  # place player
if player_rect.colliderect(snail_rect):
print("colission") #also works with black screen???
mouse_pos = pygame.mouse.get_pos()
if player_rect.collidepoint(mouse_pos):
pygame.mouse.get_pressed()
print(pygame.mouse.get_pressed()) #this works even with black screen????
clock.tick(60)

在while中为true before clock。打勾或打勾类型pygame.display.update()你没有更新显示,所以它是黑色的

最新更新