Search
 
SCRIPT & CODE EXAMPLE
 

C

pygame detect click

while ... # your main loop
  # get all events
  ev = pygame.event.get()

  # proceed events
  for event in ev:

    # handle MOUSEBUTTONUP
    if event.type == pygame.MOUSEBUTTONUP:
      pos = pygame.mouse.get_pos()

      # get a list of all sprites that are under the mouse cursor
      clicked_sprites = [s for s in sprites if s.rect.collidepoint(pos)]
      # do something with the clicked sprites...
Comment

how to detect mouse click in pygame

while running: # Gameloop
  for event in pygame.event.get(): # Checks all events
    if event.type == pygame.MOUSEBUTTONDOWN: # If the current event is the mouse button down event
      pos = pygame.mouse.get_pos() # Stores the mouse position
Comment

pygame detect click

is_toching = self.rect.collidepoint(mpos)
if event.type == pygame.MOUSEBUTTONUP:
     self.mouse_up_event(mpos)
     if is_toching and event.button == 1:
         self.click_event(mpos)
Comment

PREVIOUS NEXT
Code Example
C :: allow unrelated histories 
C :: factorial c program using for loop 
C :: write in file in c 
C :: arduino serial read write structure 
C :: c random list 
C :: bash check if inside lxc 
C :: golden cobblestone modpack 
C :: execution time of c program 
C :: line counter in c 
C :: add border to image android 
C :: remove from string c 
C :: arduino digital input pins 
C :: find the largest number among five numbers in c language 
C :: search array element in c 
C :: const godot gdscript 
C :: check if the c code is a palindrome 
C :: %d in c 
C :: c programing strtok use 
C :: how make a character in c scanf 
C :: how to print sizes of various data types of C 
C :: c float 
C :: initializa 2d array c 
C :: search in gz file 
C :: bootsrap textbox 
C :: printing out an array in c from user input 
C :: lichess puzzles 
C :: class in oops 
C :: 2d array in c 
C :: looping through an array in c 
C :: 1000000000 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =