我想让屏幕保持绿色一段时间并注册KEYDOWNS但我不能在pygame.time.wait函数运行时
self.screen.fill(self.red)
pygame.time.wait(self.wait)
rect = self.text.get_rect()
rect = rect.move(500,500)
self.screen.blit(self.text, rect)
if event.type == pygame.KEYDOWN:
print "Ouch"
self.lives -= 1
print self.lives
self.screen.fill((255, 255, 255))
self.text = sysfont.render("Lives: %d" % self.lives, True, (255, 255, 255))
self.screen.blit(self.text, (25, 25))
pygame.display.flip()
pygame.display.flip()
答案 0 :(得分:4)
你可以做这样的事情:(5秒= 5000毫秒)
time_to_change_color = pygame.time.get_ticks() + 5000 # 5 seconds
# main loop
while TRUE:
# place for events
if pygame.time.get_ticks() < time_to_change_color:
self.screen.fill(self.GREEN)
else:
self.screen.fill(self.BLACK)
# place for blits
pygame.display.flip()
或者像这样:
time_to_change_color = pygame.time.get_ticks() + 5000 # 5 seconds
current_background_color = self.GREEN
# main loop
while TRUE:
# place for events
if pygame.time.get_ticks() > time_to_change_color:
current_background_color = self.BLACK
self.screen.fill(current_background_color)
# place for blits
pygame.display.flip()