2

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
  • So when using pygame.mouse.get_pressed() in an if statement, use if True in pygame.mouse.get_pressed():. Otherwise, pygame.mouse.get_pressed() always seems True if you have only it in an if statement. Commented Apr 12, 2022 at 16:57

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That probably helps but my program still isn't working

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.