Ecnu CS Programming Club

ECNUCS_Programming Club

View the Project on GitHub JSYRD/ECNUCS_Programming_Club

pygame时钟

pygame的时钟也是一个类,它在pygame.time中,比如创建一个时钟对象:

fclock = pygame.time.Clock()

这样我们就有了一个名字叫fclock的时钟对象。它拥有一个我们常用的方法:

其余的方法原文po在下面,感兴趣的同学可以自行学习或者去官网查看详情:

  • tick_busy_loop()

    update the clock

    tick_busy_loop(framerate=0) -> milliseconds

    This method should be called once per frame. It will compute how many milliseconds have passed since the previous call.

    If you pass the optional framerate argument the function will delay to keep the game running slower than the given ticks per second. This can be used to help limit the runtime speed of a game. By calling Clock.tick_busy_loop(40) once per frame, the program will never run at more than 40 frames per second.

    Note that this function uses pygame.time.delay()pause the program for an amount of time, which uses lots of CPU in a busy loop to make sure that timing is more accurate.

    New in pygame 1.8.

  • get_time()

    time used in the previous tick

    get_time() -> milliseconds

    The number of milliseconds that passed between the previous two calls to Clock.tick().

  • get_rawtime()

    actual time used in the previous tick

    get_rawtime() -> milliseconds

    Similar to Clock.get_time(), but does not include any time used while Clock.tick() was delaying to limit the framerate.

  • get_fps()

    compute the clock framerate

    get_fps() -> float

    Compute your game’s framerate (in frames per second). It is computed by averaging the last ten calls to Clock.tick().