Music Overlaying Sound and Sound Control for Player

Started by Ghostlady, Sat 25/05/2024 04:35:48

Previous topic - Next topic

Ghostlady

What code would I use to make it go away if the player moves the mouse far enough away from the slider?
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Snarky

Something like:

Code: ags
#define CLOSING_DISTANCE 10

function repeatedly_execute()
{
  if(VolumeSliderGui.Visible)
  {
    if(   mouse.x < VolumeSliderGui.X - CLOSING_DISTANCE
       || mouse.x > VolumeSliderGui.X + VolumeSliderGui.Width  + CLOSING_DISTANCE
       || mouse.y < VolumeSliderGui.Y - CLOSING_DISTANCE
       || mouse.y > VolumeSliderGui.Y + VolumeSliderGui.Height + CLOSING_DISTANCE)
      VolumeSliderGui.Visible = false;
  }
  // Other repeatedly_execute stuff...
}

This checks whether the mouse cursor is outside of a box around the GUI the volume slider sits on (change to the name you actually use, of course), with the "tolerance border" around the GUI here set to 10 pixels wide in each direction. If it's outside, simply hide the GUI.

Ghostlady

I added this code to the repeatedly execute and when the slider gui pops up it immediately closes where you can't move the slider.
My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

Snarky

Well, is the mouse cursor outside of the bounds as it opens? I don't know what your GUI design looks like, but if the slider doesn't appear right where the mouse cursor is, then it might of course immediately trigger the closing condition. You should work out the region you want it to remain open within and adjust the CLOSING_DISTANCE value (or values) accordingly.

Ghostlady

My Games:

Hauntings Of Mystery Manor
Intrigue At Oakhaven Plantation
Haunting at Cliffhouse

SMF spam blocked by CleanTalk