【发布时间】:2019-10-22 08:12:31
【问题描述】:
我在 Pygame 中得到了这个小程序。它运行一个时间,每 2 秒执行一次操作。在我的代码中遗漏的这 2 秒内它到底在做什么。 现在,我可以在程序运行时按 Enter 并计算按 Enter 的时间。 我唯一的问题是,即使我使用 pygame.display.update(),字体也不会更新。它始终在屏幕上的同一位置显示数字。有人可以帮帮我吗?
import pygame
import time
pygame.init()
screen = pygame.display.set_mode((640, 480))
clock = pygame.time.Clock()
done = False
font = pygame.font.SysFont("comicsansms", 72)
start = time.time()
i=0
F = 0;
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
done = True
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
F = F + 1
text4 = font.render(str(F), True, (128, 128, 0))
screen.blit(text4,
(460 - text4.get_width() // 1, 40 + i * 20 - text4.get_height() // 2))
pygame.display.update()
clock.tick(30)
passed_time = time.time() - start
clock.tick(30)
if passed_time > 2 and i < 5:
start = time.time()
i = i + 1
pygame.display.update()
pygame.display.flip()
clock.tick(30)
screen.fill((255, 255, 255))
screen.blit(text4,
(320 - text4.get_width() // 2, 240 - text4.get_height() // 2))
pygame.display.flip()
clock.tick(60)
【问题讨论】:
标签: python function pygame display