0
左ボタンを押したときにチェックしたいと思います。私のコードでは、click = pygame.mouse.get_pressed()をチェックし、click [0] == 1をチェックして左ボタンが押されているかどうかを確認します。 これは、マウスクリックのためのアクションとして渡すものが、[0] == 1をクリックすると長くなることを意味します。私はそれがちょうど起こることを望みます。どんな助けでも大歓迎です!ゲームのマウスボタンの操作
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')を使用します。このイベントは、ボタンが「非押さ」から「押された」位置に変わったときに一度だけ作成されますが、押したままにすると作成されません。しかし、これはこの醜い 'button'関数を素敵なクラス' Button'に再構築する必要があります。 https://github.com/furas/my-python-codes/blob/master/pygame/button-hover/example-1.py – furas