如何使用pygame点亮屏幕上的帧速率?

问题描述 投票:0回答:1

[我知道我可以使用print(clock.get_fps())在外壳中打印fps,但是我想在播放时在屏幕上显示fps。

我尝试使用

fps_text = game_font.render(clock.get_fps(), True, (255, 255, 0))
win.blit(fps_text, (1000, 100))

(字体已经初始化,我在程序的其他地方使用它)

我在代码的第一行收到错误TypeError: text must be a unicode or bytes。有办法做我想做的事吗?感谢您的回答

python pygame frame-rate
1个回答
0
投票

clock.get_fps()返回int。 'render'的第一个参数是str

改为执行此操作:game_font.render(str(clock.get_fps()), True, (255, 255, 0))

© www.soinside.com 2019 - 2024. All rights reserved.