python - Tkinter game: Deleting instances -


i'm working on game competition using python , tkinter. far, it's coming along nicely, have movement, , shooting... sort of shooting. able create bullets , move them in direction want. however, want delete them when go off screen. that's part i'm having trouble with. below shooting code (which bound left mouse button) , movement code:

def shoot(self,e):     theplayer=self.find_withtag("player")      bullet=self.create_image([self.coords(theplayer)],image=self.playerup,tag="bullet")     self.bullets.append(bullet)  def movebullet(self):     bullet in self.bullets:         x1,x2,y1,y2=self.bbox(bullet)          if x1>1200:             self.move(bullet,14,0)         else:             self.delete(bullet) 

i thought deleting code work, gives me error says: "x1,x2,y1,y2=self.bbox(bullet) typeerror: 'nonetype' object not iterable"

i'm not sure means, , shooting doesn't work this. however, worked before tried deleting bullets. i'd appreciate anyone's this. thanks

without seeing code self.delete() method , code class declaration self instance of, hard tell what, exactly, wrong.

at guess, i'd you're deleting instance object bullet has moved offscreen, you're not removing list bullets[], next time call movebullet(self), iterates through self.bullets , falls down when tries move non-existant bullet.

try:

else:     self.bullets.remove(bullet)     self.delete(bullet) 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -