0
Я хотел бы проверить, когда нажата левая кнопка. В моем коде я проверяю щелчок = pygame.mouse.get_pressed(), а затем проверю, нажата ли левая кнопка, щелкнув [0] == 1. Это означает, что то, что я передаю как действие для щелчка мыши, так долго нажимает [0] == 1. Я бы хотел, чтобы это произошло только один раз. Любая помощь будет принята с благодарностью!кнопка мыши вниз в pygame
def button(text, x, y, width, height, inactive_color, active_color, action = None):
cur = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
print(click)
if x + width > cur[0] > x and y + height > cur[1] > y:
pygame.draw.rect(gameDisplay, active_color, (x,y,width,height))
if click[0] == 1 and action != None: # Button action definitions
if action == "quit":
print('quit')
return 0
if action == "intro":
print('intro')
return 1
if action == "play":
print('play')
return 2
if action == "replay":
print('replay')
#restart timer?
return 2
if action == "controls":
print('controls')
return 3
if action == "pause":
gamePause()
if action == "continue":
paused=False
else:
pygame.draw.rect(gameDisplay, inactive_color, (x,y,width,height))
text_to_button(text,BLACK,x,y,width,height)
использование 'if event.type == pygame.MOUSEBUTTONDOWN' (и' event.button == 1'). Это событие создается только один раз, когда кнопка меняет положение с 'not-press' на' нажатие', но не создается при нажатии. Но это должно было бы перестроить эту уродливую функцию 'button' в классную кнопку' Button', т.е. https://github.com/furas/my-python-codes/blob/master/pygame/button-hover/example-1.py – furas