我想写一个简单的pygame程序,其中一些框在屏幕上移动。我正在关注this example。pygame不一致更新
本教程的结构如下:
class Box(pygame.sprite.Sprite):
...
def update(self, currtime):
if self.next_update_time < current_time:
print time.time() # I added this to debug
# Do some stuff
self.next_update_time = current_time + 10
box = Box()
while True:
pygame.time.delay(10)
time = pygame.time.get_ticks()
box.update(time)
我的箱子移动,但不是非常顺利。他们加快速度并放慢一点点。当我绘制更新发生的点时,我得到this。
这看起来像是我跟随的教程中提出的设计问题吗?这是我的硬件问题吗?
编辑: 基于拉多米尔Dopieralski的回答,更好的办法是:
class Box(pygame.sprite.Sprite):
...
def update(self):
# Do some stuff
box = Box()
clock = pygame.time.Clock()
while True:
clock.tick(100)
box.update()
我刚刚注意到教程中有一个'pygame.time.delay(10)',所以这是一个愚蠢的问题。 – ajwood 2012-03-01 02:59:58
问题实际上仍然存在,只是没有像添加延迟之前那样糟糕。当我将延迟/更新降低到5时,它*非常糟糕。所以我认为这是一个有效的问题。 – ajwood 2012-03-01 03:05:49
+1为图 – Darthfett 2012-03-14 21:00:59