Python pygame在屏幕上显示变量不工作
我正在使用pygame并试图显示变量I,该变量在我的模拟中保存循环编号,该变量似乎没有显示,但是,也没有抛出错误,sim卡运行时,就好像我为尝试显示变量而添加的最后3行不在那里一样。我尝试过改变颜色(我的背景是黑色)和位置,但没有效果。代码如下:Python pygame在屏幕上显示变量不工作,python,pygame,simulation,Python,Pygame,Simulation,我正在使用pygame并试图显示变量I,该变量在我的模拟中保存循环编号,该变量似乎没有显示,但是,也没有抛出错误,sim卡运行时,就好像我为尝试显示变量而添加的最后3行不在那里一样。我尝试过改变颜色(我的背景是黑色)和位置,但没有效果。代码如下: while running: try: i += 1 if (exp.round_n > exp.total_rounds): running = False
while running:
try:
i += 1
if (exp.round_n > exp.total_rounds):
running = False
screen.fill((0, 0, 0, 0))
flag = Box2DWorld.destroy([exp.objs, exp.epucks])
#PyGameUtils.draw_contacts(screen,exp)
PyGameUtils.draw_world(screen)
exp.update(i, config)
Box2DWorld.step()
pygame.display.flip() # Flip the screen and try to keep at the target FPS
#clock.tick(Box2DWorld.TARGET_FPS)
clock.tick(60)
pygame.display.set_caption("FPS: {:6.3}{}".format(clock.get_fps(), " " * 5))
tnr = pygame.font.SysFont('Times New Roman', 30)
text = tnr.render(str(i), False, (255, 255, 255))
screen.blit(text, (3,3))
你必须改变指令的顺序。将文本设置为
blit()
至屏幕后,更新主循环末尾的显示
运行时:
尝试:
i+=1
如果(经验轮数>经验总轮数):
运行=错误
屏幕填充((0,0,0,0))
flag=Box2DWorld.destroy([exp.objs,exp.epucks])
#PyGameUtils.draw_联系人(屏幕,exp)
PyGameUtils.draw_世界(屏幕)
exp.update(i,配置)
Box2DWorld.step()
#pygame.display.flip()#