I'm trying to make a button that plays a sound when hovering above it with the cursor
So far I created a class which extends the scene2d TextButton and I'm adding a FocusListener. The problem is that the sound is played a lot of times when hovering because this event fires not only once but as long as the button is focused.
//When button is hovered
this.addListener(new FocusListener() {
public boolean handle(Event e) {
SoundManager.play(hoverSound);
return true;
}
});
I also tried to make a variable soundPlayed which toggles if the sound is played once but this leads to the sound playing only one time because I don't know how to detect if the button is not focused anymore so i can reset the variable.
Thanks for the help.