如何在pygame中制作基于时间的循环
到目前为止,我已经做了一个每秒60帧的游戏,但我需要让角色在走路时有动画。我查了好几天的资料,但还是不知道怎么让这个基于时间的循环工作。如果你能给我一个例子并解释一下是怎么回事,我会非常感激的!
1 个回答
0
每隔1秒(1000毫秒)更换一次动画 - 使用pygame的计时功能。
current_time = pygame.time.get_ticks()
next_move = current_time + 1000 # 1s = 1000ms
# mainloop
while True:
current_time = pygame.time.get_ticks()
if next_move <= current_time:
change_animation()
next_move = current_time + 1000
这段代码不依赖于每秒帧数(FPS)。