私はそれを選択しようとしています。選択するオプションのグループを生成し、上矢印と下矢印を使用して現在のオプションを強調表示し、これを押すと、そのオプションに含まれる関数が呼び出されます。pygame選択メニューナビゲーション矢印キーを使用して返信
私はそれをきれいにしましたが、目的の結果を得るためにいくつかのことを試していました。
選択機能が
def selection(text, selected_status, x, y, function):
if selected_status:
fill_rect(black, x, y, display_width - x, font_size + 2)
fill_rect(settings[3], x, y, display_width - x, font_size +2)
message_to_screen("["+ text + "]", settings[3], black, x, y)
if event_handler() == pygame.K_RETURN:
function()
return True
elif not selected_status:
fill_rect(black, x, y, display_width - x, font_size + 2)
message_to_screen("["+ text + "]", black, settings[3], x, y)
return False
自体が正常に動作選択ハンドラが問題です。彼らが働くためには、特定の時間に矢印キーを押す必要があるようです。 event_handlerは現在押されているキーをつかんで返します。全体的にそれはちょうど壊れた混乱です。代わりに、単にキーが今押下されたか否かをチェックするの
def selection_handler(selection_param_array, x, y):
text_array = selection_param_array[0]
selected_status_array = selection_param_array[1]
function_array = selection_param_array[2]
index = 0
chosen = False
original_y = y
while not chosen:
y = original_y
for i in range(len(selected_status_array)):
if selected_status_array[i] == selected_status_array[index]:
selected_status_array[i] = True
else:
selected_status_array[i] = False
selection(text_array[i], selected_status_array[i], x, y, function_array[i])
y += font_size
if event_handler() == pygame.K_UP and index > 0:
index -= 1
elif event_handler() == pygame.K_DOWN and index < len(selection_param_array):
index += 1
elif event_handler() == pygame.K_RETURN:
chosen = True
function_array[index]()
pygame.display.update()
イベントハンドラは実際には非常にコードなので、イベントを反復するときに見つけたものを返します –
その場合、おそらく別の問題があります。 event_handlerコードは、現在のコードで3回呼び出されています。つまり、呼び出されるたびにイベントキューをクリアするので、各イベントは1回の比較でしか表示されません。 – LeopardShark