Loading...
Logo
Processing Forum

Mouse over sound

in Programming Questions  •  1 year ago  
Ok, I've programmed my menu options. They highlight green whenever the mouse cursor is over them and return to black when my mouse isn't over it.

Now I want a sound to play once when I've highlighted an option. Here's what I'm basically doing (not real code):

Copy code
  1. void draw()
  2. {
  3.       int text_r = 0;
  4.       int text_g = 0;
  5.       int text_b = 0;

  6.       if (mouseOverOption() == true)
  7.       {
  8.             text_g = 200;
  9.             playSound();
  10.       }

  11.       drawText("Option", text_r, text_g, text_b);
  12. }
The problem is that if my mouse lingers on an option, the sound plays countless times rapidly. How can I change my code so that sound is only played once when you highlight an option?

Thanks.

Replies(3)

Have a var storing the last text sound was played upon.

Play sound only when current sound is different from that var.


No, it's one sound being played for all the options. That wouldn't work.
Then transform the above proposal to:
"Have a var storing the last menu item that was hovered. Play sound only when current menu item is different from that var."