Xer*_*ath 5 python pygame python-3.x
如下面的代码所示,我有一个基本的计时器系统
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)
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何获取当前时间毫秒以及如何创建增量时间,因此可以在更新方法中使用它?
从文档中: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
Run Code Online (Sandbox Code Playgroud)