“eventos de ratón de pygame” Código de respuesta

Pygame obtenga la posición del mouse

x,y = pygame.mouse.get_pos()
#get the mouse cursor position
#get_pos() -> (x, y)
#Returns the X and Y position of the mouse cursor.
#The position is relative to the top-left corner of the display.
#The cursor position can be located outside of the display window,
#but is always constrained to the screen.
8Dion8

Pygame detectar clic

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...
Breakable Baboon

Ratón en Pygame

pygame.mouse.get_pos() #-> get the mouse cursor position on the screen in taple
#-> (x, y)

if event.type == pygame.MOUSEBUTTONDOWN:
    print(event.button)

#------------------------#
1 - left click
2 - middle click
3 - right click
4 - scroll up
5 - scroll down
#------------------------#
Shakedcode

eventos de ratón de pygame

import pygame
pygame.init()

screen = pygame.display.set_mode((500,300))
thing = 0
while thing < 100000000:
    thing += 1

event = pygame.event.get()
print (event)
pygame.quit()
Hilarious Hamster

pygame.eventos

keys=pygame.key.get_pressed()
if keys[K_LEFT]:
    location-=1
    if location==-1:
        location=0
if keys[K_RIGHT]:
    location+=1
    if location==5:
        location=4
Energetic Eland

Respuestas similares a “eventos de ratón de pygame”

Preguntas similares a “eventos de ratón de pygame”

Más respuestas relacionadas con “eventos de ratón de pygame” en TypeScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código