[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] more list problems



An idiomatic way would be this:

if event.button == 3:
    rect = [r for r in rect if not r.collidepoint(*event.pos)]

--Noah

On Sep 20, 2007, at 8:18 PM, Eric Hunter wrote:

so I have been able to write pygame.Rect rectangles into rect-type lists. but now I'm trying to delete unwanted rectangles that are printed to the screen.

when I draw one at a time, I can only delete the last drawn rectangle before deleting the previous ones. I want to be able to delete any rectangle at any time without problems. I've come close but have run into a wall.

below is the "deleting rect" section. if anyone needs more then what's provided i can provide it upon request.

thanks in advance.

[code]
if event.button == 3:
mousexTEMP, mouseyTEMP = pygame.mouse.get_pos()
                                for i in range(0, len(rect)):
if rect[i].collidepoint (mousexTEMP, mouseyTEMP):
                                            del rect[i]
                                                numRect -= 1
[/code]