【发布时间】:2016-04-03 09:07:37
【问题描述】:
Python 版本:3.5.1 和 PyGame 版本:1.9.2a0
我的主要目标是在屏幕上闪烁图像。开 0.5 秒,关 0.5 秒。
我知道以下可以工作 60fps
frameCount = 0
imageOn = False
while 1:
frameCount += 1
if frameCount % 30 == 0: #every 30 frames
if imageOn == True: #if it's on
imageOn = False #turn it off
elif imageOn == False: #if it's off
imageOn = True #turn it on
clock.tick(60)
但我认为计算 int 中的帧数并不实际。最终我的帧号将太大而无法存储在 int 中。
如何在不将当前帧(在本例中为 frameCount)存储为整数的情况下每 x 秒闪烁一次图像?或者这实际上是最实用的方法吗?
【问题讨论】:
-
请注意,python Ints 不限于 32 位:它们会自动转换为“bigint”。另请注意,在 60 fps 时,您的游戏需要运行大约 2.3 年才能需要超过 32 位。
-
有趣点大安。同样,Racialz,如果您担心它,您可以有一个 if 语句可以重置它。 if frameCount > 1000000: frameCount = 0 编辑:答案之一解决了我之前所说的
标签: python python-3.x pygame