我在python中有一个可以工作的数字时钟,但是在pygame中我一直试图使它成为可视化的。在
时钟的代码工作,但它只是不显示任何东西,即使我已经使用了.blit这样做。在
这个想法是让计时器显示每分钟(秒),小时(每60秒)和天(每12个游戏小时)。这将出现在左上角。在
这是我的代码:import sys, pygame, random, time
pygame.init()
#Screen
size = width, height = 1280, 720 #Make sure background image is same size
screen = pygame.display.set_mode(size)
done = False
#Animation
A1=0
A2=0
#Time Info
Time = 0
Minute = 0
Hour = 0
Day = 0
counter=0
#Colour
Black = (0,0,0)
White = (255, 255, 255)
#Fonts
Font = pygame.font.SysFont("Trebuchet MS", 25)
#Day
DayFont = Font.render("Day:"+str(Day),1, Black)
DayFontR=DayFont.get_rect()
DayFontR.center=(985,20)
#Hour
HourFont = Font.render("Hour:"+str(Hour),1, Black)
HourFontR=HourFont.get_rect()
HourFontR.center=(1085,20)
#Minute
MinuteFont = Font.render("Minute:"+str(Minute),1, Black)
MinuteFontR=MinuteFont.get_rect()
MinuteFontR.center=(1200,20)
#Images
Timer=pygame.time.get_ticks
Clock = pygame.time.Clock()
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
screen.fill(White)
#Timer
if Time<60:
time.sleep(1)
Minute=Minute+1
if Minute == 60:
Hour=Hour+1
Minute=0
if Hour==12:
Day=Day+1
Hour=0
if A1==0:
A1=A1+1
A2=A2+1
time.sleep(1)
if A1==1 or A2==1:
A2=A2-1
A1=A1-1
if A1==1:
screen.blit(MinuteFont, MinuteFontR)
screen.blit(HourFont, HourFontR)
screen.blit(DayFont, DayFontR)
if A2==0:
screen.fill(pygame.Color("White"), (1240, 0, 40, 40))
pygame.display.flip()
Clock.tick(60)
pygame.quit()
抱歉,如果这是努比,但任何帮助,谢谢