簡體   English   中英

pygame:當前時間毫秒和增量時間

[英]pygame: current time millis and delta time

正如您在下面的代碼中看到的,我有一個基本的計時器系統

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.time.get_ticks pygame.init()以來的毫秒數。

Delta-time只是自上一幀以來經過的時間量,如:

t = pygame.time.get_ticks()
# deltaTime in seconds.
deltaTime = (t - getTicksLastFrame) / 1000.0
getTicksLastFrame = t
ms = clock.tick(30)

該函數返回自上次調用以來的毫秒數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM