nin*_*key 12
对于动画/冷却时间等:如果你想"等待",但仍然运行代码,你可以使用:pygame.time.get_ticks
class Unit():
def __init__(self):
self.last = pygame.time.get_ticks()
self.cooldown = 300
def fire(self):
# fire gun, only if cooldown has been 0.3 seconds since last
now = pygame.time.get_ticks()
if now - self.last >= self.cooldown:
self.last = now
spawn_bullet()
Run Code Online (Sandbox Code Playgroud)
一般来说,对于 Python,您需要查看sleep库。
然而,对于 Pygame,使用pygame.time.delay()将根据 CPU 时钟暂停给定的毫秒数,以提高准确性(与 pygame.time.wait 相反)。
| 归档时间: |
|
| 查看次数: |
18823 次 |
| 最近记录: |