2011-06-12 35 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