ppizarror / pygame-menu

A menu for pygame. Simple, and easy to use
https://pygame-menu.readthedocs.io/
Other
544 stars 141 forks source link

Widget selection sound not working #399

Closed vnmabus closed 2 years ago

vnmabus commented 2 years ago

Describe the bug The widget selection sound is not playing when I change the selected widget.

To Reproduce As an example, use the example code that added the widget selection sound:

import pygame
import pygame_menu

pygame.init()
surface = pygame.display.set_mode((600, 400))

def set_difficulty(value, difficulty):
    pass

def start_the_game():
    print('Press button')

engine = pygame_menu.sound.Sound()
engine.set_sound(pygame_menu.sound.SOUND_TYPE_WIDGET_SELECTION, pygame_menu.sound.SOUND_EXAMPLES[-1])

menu = pygame_menu.Menu('Welcome', 400, 300, theme=pygame_menu.themes.THEME_BLUE)
menu.set_sound(engine, recursive=True)

menu.add.text_input('Name :', default='John Doe')
menu.add.selector('Difficulty :', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
menu.add.button('Play', start_the_game)
menu.add.button('Quit', pygame_menu.events.EXIT)
menu.center_content()

menu.mainloop(surface)

Expected behavior When you move between widgets, the sound should be played.

vnmabus commented 2 years ago

It seems that when used the keys instead of a joystick to select the widget, apply_sound is not set to True: https://github.com/ppizarror/pygame-menu/blob/41d3d5094b8dfff1b484e08e4e44b11f54fdd020/pygame_menu/menu.py#L2457

ppizarror commented 2 years ago

Hi @vnmabus. Fixed in #402