正如您在下面的代码中看到的,我有一个基本的计时器系统
done = False
clock = pygame.time.Clock()
# Create an instance of the Game class
game = space_world.SpaceWorld()
# Main game loop
while not done:
# Process events (keystrokes, mouse clicks, etc)
done = game.process_events()
# Update object positions, check for collisions...
game.update()
# Render the current frame
game.render(screen)
# Pause for the next frame
clock.tick(30)
我的问题是,如何获取当前时间毫秒数以及如何创建增量时间,以便在更新方法中使用它?
最佳答案
来自文档:pygame.time.Clock.get_time
将返回前两次调用 Clock.tick
之间的毫秒数。
还有pygame.time.get_ticks
这将返回自调用 pygame.init()
以来的毫秒数。
增量时间就是自上一帧以来耗时量,例如:
t = pygame.time.get_ticks()
# deltaTime in seconds.
deltaTime = (t - getTicksLastFrame) / 1000.0
getTicksLastFrame = t
关于python - pygame:当前时间毫秒和增量时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24039804/