I've created a button function and it works, but if I use the function more than once on the screen then it will only work on one of the buttons and I'm not sure why.
Here is the code for the button function.
def button(x, y, w, h, action=None):
mx, my = pygame.mouse.get_pos()
for event in pygame.event.get():
if x + w > mx > x and y + h > my > y:
if event.type == pygame.MOUSEBUTTONDOWN:
action()
and here is the code where I am trying to use it, the first button which makes it start the game_loop works but the button which should quit doesn't
def game_intro():
intro = True
while intro:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.blit(bg_resize,(0,0))
gameDisplay.blit(play_resize,(100,150))
gameDisplay.blit(quit_resize,(575,150))
button(100,150,393,393,game_loop)
button(575,150,393,393,quit)
pygame.display.flip()
clock.tick(15)