how to detect mouse click in pygame

Solutions on MaxInterview for how to detect mouse click in pygame by the best coders in the world

showing results for - "how to detect mouse click in pygame"
Karl
19 Sep 2019
1while ... # your main loop
2  # get all events
3  ev = pygame.event.get()
4
5  # proceed events
6  for event in ev:
7
8    # handle MOUSEBUTTONUP
9    if event.type == pygame.MOUSEBUTTONUP:
10      pos = pygame.mouse.get_pos()
11
12      # get a list of all sprites that are under the mouse cursor
13      clicked_sprites = [s for s in sprites if s.rect.collidepoint(pos)]
14      # do something with the clicked sprites...
Erica
31 Nov 2018
1while running: # Gameloop
2  for event in pygame.event.get(): # Checks all events
3    if event.type == pygame.MOUSEBUTTONDOWN: # If the current event is the mouse button down event
4      pos = pygame.mouse.get_pos() # Stores the mouse position
similar questions
queries leading to this page
how to detect mouse click in pygame