-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: new class Juego_button & Bugfix: sound repeating when hovering on buttons #35
Conversation
whenever hovering on a button the menu.ogg sound kept playing repeatedly. fixed it by adding a variable menu_sound_played to check if the sound has already been played for that hover event or not
The solution seems complex, and stops sounds under some circumstances. Please look through the commit history to see when the problem began, and tell us which commit is the cause? |
Hi @quozl, I have checked out previous versions of the activity and this was the oldest commit I was able to run as it's the port to Gtk3. Running it makes it evident that the issue existed even then and the implementation for playing the sound was done in this manner to begin with, a MOUSEMOTION event is detected and a sound is played if the mouse is within the button's co-ordinates. This can be seen here in the v1 initial commit. As you specified, the sound doesn't play in some scenarios, this happens when we move too quickly between buttons. This is due to the buttons being too close and if it would be desirable, I can accommodate this by moving these buttons so that the gap between them is increased. moreover, I have noticed the coordinates of the buttons are hard coded everywhere and even the checks are repeated multiple times so, that could also be improved by turning the buttons into their own separate classes and having methods to check hovers and running callbacks. would this be desirable? |
Thanks for checking. I went back to the first commit and looked at juego.py, which does not depend on GTK, and found the same; the menu sound is ordered to play on mouse motion event, and there is no check for if the sound is already playing. I think you are observing a feature of the newer pygame SDL Mixer, which may allow more channels now than a previous version of pygame. Latest version allows eight channels. This is a limit on number of simultaneous sounds. I don't remember it being so generous. It would be better to detect entry into the area rather than detect motion within it. Yes, there are too many special numeric constants. You may be interested in https://github.com/orgs/sugarlabs/projects?type=classic which lists the display resolution project in more detail, with background on the overall problem that affects many of the pygame and GTK activities. |
… to avoid hardcoding
…he buttons, hover effects, sound playing and mouseclicks
Hi @quozl I have created a new class to avoid hard coding the values for checking hovers and mouse clicks |
Thanks. Looks good. |
How to reproduce the bug?
Cause
The issue was caused due to there not being any checks in place to see if the sound has already been played or not. the implementation was done by checking for a pygame event of type
MOUSEMOTION
and whenever the mouse moved and the mouse coordinates lied within a button, it played the sound.Fix
I have added a variable
menu_sound_played
which is initially set to False and is set to True whenever a sound is played within a hover event. it is set to False again whenever the cursor moves out of a button, sounds are only played when the value is False. This way, the sounds do not repeat whenever moving the cursor