所以基本上我只是想在python中使用pygame做一些事情。这是代码的一部分,其余代码不会影响这一点,所以我
attrs
正如您所看到的,它的目的是创建一个全屏窗口,只有一些字母可以进入" 3"," 2"," 1& #34;在突破并执行其余代码之前。
一切看起来都不错,但问题是什么都没有出现。我只是得到了一个黑色的全屏窗口,就像我想要的那样,但没有出现白色文字。我究竟做错了什么?
答案 0 :(得分:3)
pygame.display
在内存(缓冲区)中创建screen
,surface
,并在此表面上绘制所有blit
。您必须使用display.flip()
或display.update()
在屏幕/显示器上发送此表面/缓冲区。
编辑:示例代码
import pygame
# --- constants --- (UPPER_CASE names)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
# --- classes --- (CamelCase names)
# empty
# --- functions --- (lower_came names)
# empty
# --- main ---
# - init -
pygame.init()
screen = pygame.display.set_mode((800, 600))
screen_rect = screen.get_rect()
# - objects -
default_font = pygame.font.get_default_font()
font_renderer = pygame.font.Font(default_font, 45)
# - mainloop -
count_time = 1
running = True
while running:
# --- events ---
for event in pygame.event.get():
# close window with button `X`
if event.type == pygame.QUIT:
running = False
# close window with key `ESC`
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
# --- updates (without draws) ---
label = font_renderer.render(str(count_time), True, WHITE)
label_rect = label.get_rect()
# center on screen
label_rect.center = screen_rect.center
count_time += 1
if count_time >= 4:
running = False
# --- draws (without updates) ---
screen.fill(BLACK)
screen.blit(label, label_rect)
pygame.display.flip()
# --- speed ---
# 1000ms = 1s
pygame.time.delay(1000)
# - end -
pygame.quit()