pygame.time--监控时间的模块

import pygame

pygame.init()
screen = pygame.display.set_mode((96, 60))
pygame.display.set_caption("时间模块")

t=pygame.time.get_ticks()  #获取以毫秒为单位的时间
#返回自 pygame_init() 调用以来的毫秒数。在pygame初始化之前,这将始终为0

t1=pygame.time.wait(5000)  #暂停5000毫秒
#返回实际暂停的毫秒数
#此函数会暂停进程以与其他程序共享处理器

t1=pygame.time.delay(5000)  #暂停5000毫秒
#此功能将使用处理器
#返回实际暂停的毫秒数

print(t1)

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    pygame.display.update()

import pygame

pygame.init()
screen = pygame.display.set_mode((96, 60))
pygame.display.set_caption("时间模块")

pygame.time.set_timer(pygame.MOUSEBUTTONDOWN, 2000) #以一定的时间间隔自动产生某事件
#每个2000毫秒自动产生一次鼠标按下事件
#参数1:事件
#参数2:间隔时间
#要禁用事件的计时器,请将milliseconds参数设置为0
#每种事件类型都可以附加一个单独的计时器

i=0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
print(i,'鼠标键按下了', event)
i+=1

pygame.display.update()
#运行此程序,你会看到,每个2000毫秒自动产生一次鼠标按下事件



 
import pygame

pygame.init()
screen = pygame.display.set_mode((96, 60))
pygame.display.set_caption("时间模块")

clock = pygame.time.Clock()  # 创建时钟对象
i=0
while True:
    t=clock.tick(60)  # 每秒最多循环60次
    #每次计算上次到此时的时间,如果低于时间间隔,会等待
    #应该每帧调用一次此方法
    #返回值:自上一次调用以来经过的毫秒数
    #请注意,此函数使用SDL_Delay函数,该函数在每个平台上都不准确,但不会占用太多CPU

    print(i,t)
    i+=1
    x = 0
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    for ii in range(3000000):
        x=x+1
    pygame.display.update()
import pygame

pygame.init()
screen = pygame.display.set_mode((96, 60))
pygame.display.set_caption("时间模块")

clock = pygame.time.Clock()
i=0
while True:
    t=clock.tick_busy_loop(60)  # 每秒最多循环60次
    #每次计算上次到此时的时间,如果低于时间间隔,会等待
    #应该每帧调用一次此方法
    #返回值:自上一次调用以来经过的毫秒数
    #请注意,此函数使用 pygame.time.delay,在繁忙的循环中使用大量CPU以确保时间更准确

    print(i,t)
    i+=1
    x = 0
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    for ii in range(3000000):
        x=x+1
    pygame.display.update()
q=clock.get_time()  #返回前两次tick()或tick_busy_loop()之间传递的毫秒数
q=clock.get_rawtime() #返回前两次tick()或tick_busy_loop()之间传递的毫秒数
    #类似于 Clock.get_time(),但不包括  Clock.tick() 延迟限制帧速率时使用的任何时间
q=clock.get_fps()  #返回实际时钟帧率
    #以每秒帧数为单位。它是通过平均最后十次调用来计算的

原文地址:https://www.cnblogs.com/liming19680104/p/13111508.html