2011-06-12 108 views
-1
 def colision(self): 
     if self.coords(self.bola)[1]<50: 
      self.boladir=1 
     if self.coords(self.bola)[1]>870: 
      self.jugando=0 
      self.pierde() 
#  ladrillos=self.find_withtag("brick") 

    def mueve_bola(self): 
     if self.jugando: 
      if self.boladir==0: 
        self.move(self.bola,0,-10) 
      elif self.boladir==1: 
        self.move(self.bola,0,10) 
     self.colision() 
     root.after(velocidad_bola,self.mueve_bola) 

回答

1

colision调用本身,所以本场比赛开始时,这将每隔20毫秒调用。 mueve_bola also calls itself every 20ms. However, mueve_bola _also_ calls colision . So, every 20ms, colision creates another unending stream of calls to itself every 20ms. 20 ms later mueve_bola calls colision again, which again starts another stream of calls every 20ms. After just one second colision is being called 50 times every 20ms. After two seconds it will be 100 calls to colision every 20 ms. Do you see the problem? In very little time you will have millions of calls to colision每秒钟。

您只需要在移动物体时计算碰撞,所以不需要每20ms调用一次自身。每次更新显示时只需要调用一次。

我建议你创建一个每40ms左右调用一次的方法。在这里你可以一次调整所有的坐标。更新行的坐标,然后更新玩家的桨,然后更新球,然后检查碰撞。

+0

太棒了!是的,现在我看到了我做出的巨大错误^^你绝对是对的!我会尽力按照你的说法去做:单一方法移动所有东西将会更容易实现......谢谢! – dhcarmona 2011-06-13 20:30:50

相关问题