SUGGESTION or help: Button.MouseOverSound()

Started by Dave Gilbert, Wed 03/03/2010 20:44:44

Previous topic - Next topic

Dave Gilbert

I was thinking it would be nice to be able to script mouseover sounds for buttons, so they play ONCE when you move the mouse over them. 

I tried to simulate this with the code below:

Code: ags

 GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);

 if (theControl == btn_a1) 
    if (IsChannelPlaying(6)==0) 
       PlaySoundEx(56, 6);


But all this did was make the sound repeat itself over and over again.  Is there a better way to go about doing this?

Thanks!

-Dave

Goldmund

I'd make a global bool "played_mouseover", and:

if (theControl == btn_a1) {
   if ((IsChannelPlaying(6)==0)&&(played_mouseover==false)) {
      PlaySoundEx(56, 6);
      played_mouseover=true;
      }
  }
else played_mouseover=false;

Calin Leafshade

you might want to store *which* control the mouse was last over too since its quite possible to skip over the gap between buttons in a single game loop.

Dave Gilbert

Worked like a CHARM!  I had to do what Calin said, but yes.  It all works now.  Thanks!

Kweepa

I made a module to do this (for future reference):
http://www.kweepa.com/step/ags/tech/ButtonMouseOverSound.zip
It uses an extender function so you can just put something like this in the global script game_start:
btnInvOK.SetMouseOverSound(aBonk, aDonk);

The second parameter is the mouse off sound. Both params can be null.
Steve
Still waiting for Purity of the Surf II

Dualnames

You won the innovation award! Don't be greedy with the lifetime. Think of poor Andail!! :D
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Dave Gilbert


subspark

It would be cool to have support for a looping sound for mouse over like a low humming or something. Tying it in with the new AGS audio system and its repeate/play once properties for this would be good.

Cheers,
Sparky.


Quote from: Kweepa on Thu 04/03/2010 21:53:15I made a module to do this (for future reference):
http://www.kweepa.com/step/ags/tech/ButtonMouseOverSound.zip
It uses an extender function so you can just put something like this in the global script game_start:
btnInvOK.SetMouseOverSound(aBonk, aDonk);


The second parameter is the mouse off sound. Both params can be null.
Steve

Does anyone have this module in their files?


Khris

I wrote my own version; it works just like Steve's:

  btnInvOK.SetMouseOverSound(aBonk, aDonk);

The second parameter is the mouse off sound. Both params can be null.

https://drive.google.com/file/d/1UbveGm-lV2KM4OkboO1aJGgBLKhHE66d/view?usp=sharing

I had been looking for something that would simplify this task for a long time. Thank you very much, Khris!

SMF spam blocked by CleanTalk