Answers for "on mouseclick pygame"

0

event.type == pygame.MOUSEBUTTONDOWN click

def handle_event(self, screen, event, player):
        if event.type == pygame.QUIT:
            sys.exit()

        if event.type == pygame.MOUSEMOTION:
            pygame.draw.rect(screen, BACKGROUND, (0,0, self.screen_width, SQUARESIZE))
            posx = event.pos[0]
            if player == 1:
                pygame.draw.circle(screen, P1STONE, (posx, int(SQUARESIZE/2)), RADIUS)
            else:
                pygame.draw.circle(screen, P2STONE, (posx, int(SQUARESIZE/2)), RADIUS)
            pygame.display.update()    
            return None
        
        if event.type == pygame.MOUSEBUTTONDOWN:
            pygame.draw.rect(screen, BACKGROUND, (0,0, self.screen_width, SQUARESIZE))
            posx   = event.pos[0]
            action = int(np.floor(posx/SQUARESIZE))
            return action
Posted by: Guest on July-11-2020
0

pygame onclick

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...
Posted by: Guest on August-22-2021

Python Answers by Framework

Browse Popular Code Answers by Language