Mouse click isn't being recognized

Viewed 23

I am trying to make a black cell become a white cell when clicked, and vise versa. The problem that I can't seem to solve is that no matter what function I use, my program doesn't recognize when I click my mouse. I've tried just about every search result on both google and answer on stack overflow, but nothing happens. This is what I am currently using.

 def update(self, event_list):
        for event in event_list:
            if event.type == pygame.MOUSEBUTTONDOWN:
                if self.rect.collidepoint(event.pos):
                    self.alive = not self.alive
        if self.alive:
            self.image = self.alive_image
        else:
            self.dead_image
   #main loop
   while gen:
       event_list = pygame.event.get()
       for event in event_list:
           if event.type == pygame.QUIT:
               run = false

       all_cells.update(event_list)

       clock.tick(60)
   pygame.quit()

I also tried all the usual functions like pygame.mouse.get_press() and self.rect.collidepoint(). What should I try?

1 Answers

You'll need to replace your

        if self.alive:
            self.image = self.alive_image
        else:
            self.dead_image

With

        if self.alive:
            self.image = self.alive_image
        else:
            self.image = self.dead_image

As at self.dead_image the code isn't doing anything.

Related