Python精灵模块的Clock指令

所有命令 单独命令 屏幕命令 角色命令

单独命令 >> Python精灵模块的Clock指令

简介:用于固定fps的时钟对象。
例子:
from sprites import Group,Clock,Sprite

for x in range(3):
    b = Sprite(tag='bug')
    b.gotorandom()

bugs = Group('bug')  # 收集所有标签为bug的对象

clock = Clock()      # 新建时钟对象
while True:
    for bug in bugs:
        bug.fd(1)
        bug.left(1)
    # 如果上面的代码没有在1/60秒运行完毕,
    # 则下面的代码会补足到1/60秒,以便循环在1/60秒刚好完成
    clock.tick(60) 

writed by lixingqiu 关注"异编程"微信公众号,获取更多关于Python精灵模块的咨讯: