vendredi 5 juin 2020

Pygame MOUSEDOWN wont stop registering

I am trying to run an event, where clicking a button replaces an image. I have tried it two ways.

  1. mouse.get_pressed(). Issue: Once I release the mouse, the image disappears. I feel like this would be an easier approach, but I'm new to pygame and don't know how to do it.
  2. MOUSEBUTTONDOWN. Issue: When I hit play, it infinitely runs the MOUSEBUTTONDOWN event. I know this because I put a print statement after, and it just nonstop prints in the terminal. Here's my code. If you need to see more, please let me know, thanks!
def replace(x, y):
    transparent = (0,0,0,0)
    replaceImg = pygame.image.load("tree.png")
    if pygame.MOUSEBUTTONDOWN:
        print("nope")
        level1Img.fill(transparent)
        screen.blit(replaceImg, (x, y))
        pygame.display.update()
running = True
while running:
....
   replace(level1X, level1Y)
   pygame.display.update()

Aucun commentaire:

Enregistrer un commentaire